我尝试通过翻新呼叫此请求
我的代码:
Map<String, String> parameters = new HashMap<>();
Clientn client = new Clientn();
final WaselJsonPlaceHolderApi apiService = client.getClient().create(WaselJsonPlaceHolderApi.class);
Call<TokenModel> call = apiService.getLoginToken( "password", "ec_user","EC_P@ssw0rd" , "0500344253", "1993");
call.enqueue(new Callback<TokenModel>() {
@Override
public void onResponse(Call<TokenModel> call, Response<TokenModel> response) {
Log.e("TAG-TAG", ""+response.errorBody());
Log.e("TAG-TAG", ""+response.body());
}
@Override
public void onFailure(Call<TokenModel> call, Throwable t) {
}
});
界面:
@FormUrlEncoded
@POST("api/CustomerAccount/LoginUserByMobile")
Call<TokenModel> getLoginToken( @Field("grant_type") String title,
@Field("app_username") String body,
@Field("app_password") String password,
@Field("mobile_number") String userId,
@Field("ver_code") String code );
客户
public class Clientn {
public static final String BASE_URL = "http://192.168.1.230/MagicWord.ECommercPlatform.API/";
public static Retrofit retrofit = null;
public static Retrofit getClient(){
if (retrofit == null){
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
但是我得到的响应为空,并且ErrorBody为E/TAG-TAG: okhttp3.ResponseBody$1@aa2472e
答案 0 :(得分:0)
我认为android在最新的API(29)中停止了对正常 http 的响应,您可以尝试使用 https 并检查是否存在相同的问题。
答案 1 :(得分:0)
我认为问题出在您的“是int或use正在使用string的ver_code。是string还是int?
答案 2 :(得分:0)
onFailure
回调可能非常有用,请尝试在其上添加t.printStacktrace()
。
此外,不要像在Log上的字符串那样传递对象,因为它只会打印您不需要的地址。
答案 3 :(得分:0)
保持字段名和变量名相同
示例:
@Field("grant_type") String grant_type, @Field("app_username") String app_username,@Field("app_password") app_password
这样您就不会感到困惑。
我认为请求方法应为 POST 因为在代码中请求方法是 POST ,但是在屏幕快照中,请求方法是 GET