Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrofit display request details - body, headers, etc

I can't seem to find anything in Retrofit docs regarding how to display any Request details.

Specifically, I want to see JSON from POST Request Body.

The problem is that my request to the server fails with no details message, and I suspect that something is wrong on my side.

like image 227
AAverin Avatar asked Dec 05 '22 08:12

AAverin


2 Answers

Maybe there is a better way to achieve this, but you can configure your log level using the RestAdapter.Builder like:

   RestAdapter.Builder builder=...
   builder.setLogLevel(LogLevel.FULL).setLog(new RestAdapter.Log() {
            public void log(String msg) {
               Log.i("retrofit", msg);
            }
        });
like image 53
Felix Avatar answered Feb 16 '23 01:02

Felix


here is an updated answer for retrofit 2.0

 HttpLoggingInterceptor body = new HttpLoggingInterceptor();
        body.setLevel(HttpLoggingInterceptor.Level.BODY);
        builder.addInterceptor(body);

        OkHttpClient client = builder.build();

        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .client(client)
like image 34
bsautner Avatar answered Feb 16 '23 01:02

bsautner