我在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;
}
答案 0 :(得分:1)
您收到错误是因为您首先在baseurl
中添加了查询参数。
您的网址:http://192.138.0.100/Client.asmx?op=Client_Login/api/{MobileNo}/{Pass}/{AppVer}
它应该是这样的:http://192.138.0.100/Client_Login/api/{MobileNo}/{Pass}/{AppVer}
查询参数始终位于URL的末尾
请检查您的网址。
正如您在评论中提到的,您可以通过以下方式执行此操作:
public interface ApiInterface {
@GET("api/")
Call<Login> authenticate(@Query("MobileNo") String MobileNo, @Query("Pass") String password, @Query("AppVer") String AppVer);
@POST("api/")
Call<Login> registration(@Query("MobileNo") String MobileNo, @Query("Pass") String password, @Query("AppVer") String AppVer);
}