【发布时间】:2018-12-18 10:22:59
【问题描述】:
当我运行应用程序并填写电子邮件/密码时,它显示空响应(response.body() != null && response.isSuccessful()) 当我登录时,onFailure() 不显示任何内容,onResponse() 显示空。我该如何解决这个问题?
MainApi,
public final class MainApi {
private static String BASE_URL = "http://www.eg.com/";
private static Retrofit.Builder builder = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.client(new OkHttpClient());
public MainApi() {
}
public static <S> S createService(Class<S> serviceClass) {
Retrofit retrofit = builder.build();
return retrofit.create(serviceClass);
}
}
MainService 接口,
public interface MainService {
@Headers({"Content-Type: application/json", "Authorization: Bearer fafafafafafa"})
@FormUrlEncoded
@POST("auth")
Call<Auth> postAuth(@Field("email") String email,
@Field("password") String password;
}
活动,
Call<Auth> call = MainApi.createService(MainService.class).postAuth(edt_email.getText().toString(), edt_password.getText().toString());
【问题讨论】:
-
你应该整合
HttpLoggingInterceptor来检测正在发生的事情 -
你的响应码是什么?
-
@ArbenMaloku 当
call.enqueue,@Override public void onResponse(Call<Auth> call, Response<Auth> response) -
@PPL 通常你必须得到一个响应码see here。您可以使用这段代码
response.code()获取此代码,当您得到它时,请在此处发布,也许我们可以帮助您。
标签: android json api retrofit2 response