相关疑难解决方法(0)

使用Retrofit 2进行记录

我正在尝试获取请求中发送的确切JSON.这是我的代码:

OkHttpClient client = new OkHttpClient();
client.interceptors().add(new Interceptor(){
   @Override public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
      Request request = chain.request();
      Log.e(String.format("\nrequest:\n%s\nheaders:\n%s",
                          request.body().toString(), request.headers()));
      com.squareup.okhttp.Response response = chain.proceed(request);
      return response;
   }
});
Retrofit retrofit = new Retrofit.Builder()
   .baseUrl(API_URL)
   .addConverterFactory(GsonConverterFactory.create())
   .client(client).build();
Run Code Online (Sandbox Code Playgroud)

但我只在日志中看到这个:

request:
com.squareup.okhttp.RequestBody$1@3ff4074d
headers:
Content-Type: application/vnd.ll.event.list+json
Run Code Online (Sandbox Code Playgroud)

我怎么做正确的记录,考虑到拆除setLog()setLogLevel()我们使用了改造1使用哪个?

java retrofit retrofit2 okhttp3

287
推荐指数
8
解决办法
14万
查看次数

标签 统计

java ×1

okhttp3 ×1

retrofit ×1

retrofit2 ×1