我想要获取请求中发送的完整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();
但是我只在日志中看到这个:
request:
com.squareup.okhttp.RequestBody$1@3ff4074d
headers:
Content-Type: application/vnd.ll.event.list+json
考虑到Retrofit 1中我们曾使用的setLog()
和setLogLevel()
被移除了,我该如何进行正确的日志记录呢?
compile 'com.squareup.okhttp3:logging-interceptor:3.3.1'
。此依赖是用于记录网络请求和响应的日志拦截器。 - jayellos