Android 改装:来自gson改装车身的原始响应车身
我正在使用以下库进行改装Android 改装:来自gson改装车身的原始响应车身,android,gson,retrofit,okhttp,interceptor,Android,Gson,Retrofit,Okhttp,Interceptor,我正在使用以下库进行改装 'com.squareup.retrofit2:retrofit:2.5.0' 'com.squareup.okhttp:okhttp:2.7.5' 'com.squareup.retrofit2:converter-gson:2.5.0' 'com.squareup.okhttp3:logging-interceptor:3.10.0' 如何在onResponse回调中获取原始响应?我已经搜索过了,得到了很多解决方案,但现在都没有用。我尝试了response.raw
'com.squareup.retrofit2:retrofit:2.5.0'
'com.squareup.okhttp:okhttp:2.7.5'
'com.squareup.retrofit2:converter-gson:2.5.0'
'com.squareup.okhttp3:logging-interceptor:3.10.0'
如何在onResponse回调中获取原始响应?我已经搜索过了,得到了很多解决方案,但现在都没有用。我尝试了response.raw()。我还尝试了response.body().string()
,但在本例中,.string()
无法解析。我可以使用拦截器记录响应,但我需要在我的onResponse()
回调中记录该响应,而不仅仅是在logcat中打印。
我的改装客户:
public static ApiService getClient(Context context) {
if (retrofit == null) {
if (BuildConfig.FLAVOR.equalsIgnoreCase("dev")){
retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.client(okHttpClient)
.build();
}else {
retrofit = new Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BASE_URL)
.client(SelfSigningClientBuilder.createClient(context))
.build();
}
}
return retrofit.create(ApiService.class);
}
我的Retyrofit界面:
@retrofit2.http.POST("weekly_driver_earning_report/")
@retrofit2.http.FormUrlEncoded
Call<List<DailyEarnings>> getDriverWeeklyEarnings(@retrofit2.http.Field("access_token") String access_token, @retrofit2.http.Field("start_date") String start_date, @retrofit2.http.Field("end_date") String end_date);
@reformation2.http.POST(“每周司机收入报告”)
@2.http.FormUrlEncoded
调用getDriverWeekldAgents(@Reform2.http.Field(“access_token”)String access_token、@Reform2.http.Field(“start_date”)String start_date、@Reform2.http.Field(“end_date”)String end_date);
接下来,我解决了我的问题。我将调用类型定义为特定的模型类,这就是为什么response.body().string()不可访问的原因,将调用类型从List更改为ResponseBody,我可以访问response.body().string()。发布您的改型界面。此外,请使用一致的库版本。改型2.5.0依赖于okhttp>3.0。我认为必须删除ORM自动映射才能获得Call
。您必须将Call
更改为Call
,才能在回调中获得整个http响应。请也输入错误。如果您的json响应未经验证,GsonConverterFactory将无法反序列化,而是在改装中使用scalar converter factory打印原始响应。