Intercept OkHttpClient Response for Debug

I wanted to log the data retrieved by OkHttpClient for debugging purposes. After digging for a while, the process seems quite straight-forward now.

First, we create the OkHttpClient:

Then, we add an interceptor:

The interceptor code is:

The main thing to remember is that one the response has been processed, you need to create a new one and return it.


A little experiment: If you find this post and ad below useful, please check the ad out :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top