原始地址: http://omgitsmgp.com/2015/12/02/effective-okhttp/
2. Integrate with Stetho
Stetho is a lovely library by Facebook that allows you to inspect your Android application using the Chrome Developer Tools feature of Chrome.
In addition to allowing you to inspect the SQLite databases and view hierarchies of your application, Stetho allows you to inspect each request and response made by OkHttp:
This introspection is very useful for ensuring that the server is returning the HTTP headers that permit caching of resources, as well as verifying that no requests are made when cached resources should exist.
To enable Stetho, simply add a StethoInterceptor
instance to the list of network interceptors:
okHttpClient.networkInterceptors().add(new StethoInterceptor());
Then, after running your application, open Chrome and navigate to chrome://inspect
. The device and application identifier of the application should be listed. Visit its “inspect” link to open the Developer Tools, and then open the Network tab to begin monitoring requests by OkHttp.