okhttp 解析respone:


 

android,retrofit,okhttp,日志攔截器,使用攔截器Interceptor統一打印請求與響應的json:

https://blog.csdn.net/qq_37043246/article/details/73293421;

 

public class LoggingInterceptor implements Interceptor {
String TAG = "LoggingInterceptor";

@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Log.v(TAG, "request:" + request.toString());
long t1 = System.nanoTime();
okhttp3.Response response = chain.proceed(chain.request());
long t2 = System.nanoTime();
Log.v(TAG, String.format(Locale.getDefault(), "Received response for %s in %.1fms%n%s", response.request().url(), (t2 - t1) / 1e6d, response.headers()));
okhttp3.MediaType mediaType = response.body().contentType();
String content = response.body().string();
Log.i(TAG, "response body:" + content);
return response.newBuilder().body(okhttp3.ResponseBody.create(mediaType, content)).build();
} // 下面的span沒什么用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM