【发布时间】:2018-03-22 06:41:33
【问题描述】:
我在 android 中有 asp.net webservice 调用,但它给出错误baseUrl must end in /。
这是我的网址
private static String url = "http://192.138.0.100/Client.asmx?op=Client_Login";
//create Interface
public interface ApiInterface {
@GET("api/{MobileNo}/{Pass}/{AppVer}")
Call<Login> authenticate(@Path("MobileNo") String MobileNo, @Path("Pass") String password, @Path("AppVer") String AppVer);
@POST("api/{MobileNo}/{Pass}/{AppVer}")
Call<Login> registration(@Path("MobileNo") String email, @Path("Pass") String password, @Path("AppVer") String AppVer);
}
这个方法用来调用webservice但是报错
private void loginProcessWithRetrofit(final String mobilno, String pwd,String Appver){
ApiInterface mApiService = this.getInterfaceService();
Call<Login> mService = mApiService.authenticate(mobilno, pwd,Appver);
mService.enqueue(new Callback<Login>() {
@Override
public void onResponse(Call<Login> call, Response<Login> response) {
Login mLoginObject = response.body();
String returnedResponse = mLoginObject.isLogin;
Toast.makeText(LoginActivity.this, "Returned " + returnedResponse, Toast.LENGTH_LONG).show();
//showProgress(false);
if(returnedResponse.trim().equals("1")){
// redirect to Main Activity page
}
if(returnedResponse.trim().equals("0")){
// use the registration button to register
// failedLoginMessage.setText(getResources().getString(R.string.registration_message));
// mPasswordView.requestFocus();
}
}
@Override
public void onFailure(Call<Login> call, Throwable t) {
call.cancel();
Toast.makeText(LoginActivity.this, "Please check your network connection and internet permission", Toast.LENGTH_LONG).show();
}
});
}
private ApiInterface getInterfaceService() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(url)
.addConverterFactory(SimpleXmlConverterFactory.create())
.build();
final ApiInterface mInterfaceService = retrofit.create(ApiInterface.class);
return mInterfaceService;
}
【问题讨论】:
-
它给出了什么错误????/
-
baseUrl 必须以 / 结尾
-
只需像这样将“/”添加到
http://192.138.0.100/Client.asmx?op=Client_Login/。
标签: android retrofit2 android-webservice