我使用Retrofit 2,我想知道将值发送到服务器的值或结构。有什么方法我可以把'system.out.print'这样我才能知道我发送了什么?
答案 0 :(得分:1)
首先添加此
impletemtaion "com.squareup.okhttp3:logging-interceptor:LATEST_VERSION";
添加此
@Provides
@Singleton
public OkHttpClient provideClient(Context mContext, CacheInterceptor cacheInterceptor, HeaderInterceptor headerInterceptor) {
//***************
HttpLoggingInterceptor logger = new HttpLoggingInterceptor();
logger.setLevel(HttpLoggingInterceptor.Level.BODY);
//***************
return new okhttp3.OkHttpClient.Builder()
.addInterceptor(logger)
.addInterceptor(headerInterceptor)
.connectTimeout(Constant.CONNECTTIMEOUT, TimeUnit.SECONDS)
.readTimeout(Constant.READTIMEOUT, TimeUnit.SECONDS)
.writeTimeout(Constant.WRITETIMEOUT, TimeUnit.SECONDS)
.build();
}
答案 1 :(得分:0)
有关Retrofit 2的HTTPLogging拦截器,请参阅此内容
https://futurestud.io/tutorials/retrofit-2-log-requests-and-responses