Intercept OkHttpClient Response for Debug

Posted by in Software

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 🙂