Logging with Retrofit 2

前端 未结 21 1309
春和景丽
春和景丽 2020-11-22 07:33

I\'m trying to get the exact JSON that is being sent in the request. Here is my code:

OkHttpClient client = new OkHt         


        
21条回答
  •  囚心锁ツ
    2020-11-22 07:58

    I don't know if setLogLevel() will return in the final 2.0 version of Retrofit but for now you can use an interceptor for logging.

    A good example can found in OkHttp wiki: https://github.com/square/okhttp/wiki/Interceptors

    OkHttpClient client = new OkHttpClient();
    client.interceptors().add(new LoggingInterceptor());
    
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl("http://www.yourjsonapi.com")
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .build();
    

提交回复
热议问题