在带有参数和标头的android改造2中,response为null

时间:2018-12-18 10:22:59

标签: android json api retrofit2 response

当我运行一个应用程序并填写电子邮件/密码时,它显示为空响应(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());

1 个答案:

答案 0 :(得分:-1)

63