在我使用Retrofit 2时,有没有办法在发送数据之前知道值/结构

时间:2018-01-24 15:35:25

标签: android retrofit2

我使用Retrofit 2,我想知道将值发送到服务器的值或结构。有什么方法我可以把'system.out.print'这样我才能知道我发送了什么?

2 个答案:

答案 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