打印okhttp请求log信息
来源:互联网 发布:pdf文件制作软件 编辑:程序博客网 时间:2024/06/05 12:22
package com.example.kson.httpsdemo;
import android.util.Log;
import java.io.IOException;
import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
/**
* Author:kson
* E-mail:19655910@qq.com
* Time:2017/10/18
* Description:
*/
public class LogInterceptor implements Interceptor {
public static String TAG = "LogInterceptor";
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
long startTime = System.currentTimeMillis();
okhttp3.Response response = chain.proceed(chain.request());
long endTime = System.currentTimeMillis();
long duration=endTime-startTime;
okhttp3.MediaType mediaType = response.body().contentType();
String content = response.body().string();
Log.d(TAG,"\n");
Log.d(TAG,"----------Start----------------");
Log.d(TAG, "| "+request.toString());
String method=request.method();
if("POST".equals(method)){
StringBuilder sb = new StringBuilder();
if (request.body() instanceof FormBody) {
FormBody body = (FormBody) request.body();
for (int i = 0; i < body.size(); i++) {
sb.append(body.encodedName(i) + "=" + body.encodedValue(i) + ",");
}
sb.delete(sb.length() - 1, sb.length());
Log.d(TAG, "| RequestParams:{"+sb.toString()+"}");
}
}
Log.d(TAG, "| Response:" + content);
Log.d(TAG,"----------End:"+duration+"毫秒----------");
return response.newBuilder()
.body(okhttp3.ResponseBody.create(mediaType, content))
.build();
}
}
import android.util.Log;
import java.io.IOException;
import okhttp3.FormBody;
import okhttp3.Interceptor;
import okhttp3.Request;
/**
* Author:kson
* E-mail:19655910@qq.com
* Time:2017/10/18
* Description:
*/
public class LogInterceptor implements Interceptor {
public static String TAG = "LogInterceptor";
@Override
public okhttp3.Response intercept(Chain chain) throws IOException {
Request request = chain.request();
long startTime = System.currentTimeMillis();
okhttp3.Response response = chain.proceed(chain.request());
long endTime = System.currentTimeMillis();
long duration=endTime-startTime;
okhttp3.MediaType mediaType = response.body().contentType();
String content = response.body().string();
Log.d(TAG,"\n");
Log.d(TAG,"----------Start----------------");
Log.d(TAG, "| "+request.toString());
String method=request.method();
if("POST".equals(method)){
StringBuilder sb = new StringBuilder();
if (request.body() instanceof FormBody) {
FormBody body = (FormBody) request.body();
for (int i = 0; i < body.size(); i++) {
sb.append(body.encodedName(i) + "=" + body.encodedValue(i) + ",");
}
sb.delete(sb.length() - 1, sb.length());
Log.d(TAG, "| RequestParams:{"+sb.toString()+"}");
}
}
Log.d(TAG, "| Response:" + content);
Log.d(TAG,"----------End:"+duration+"毫秒----------");
return response.newBuilder()
.body(okhttp3.ResponseBody.create(mediaType, content))
.build();
}
}
阅读全文
1 0
- 打印okhttp请求log信息
- android log 信息打印
- 打印log信息
- Xcode8打印log信息
- Okhttpinterceptor____用于打印Okhttp的请求头响应头的信息
- OkHttp:拦截器之网络请求Log
- Eclipse NDK 打印LOG信息
- android ndk打印log信息
- Android NDK Log信息打印
- android jni打印log信息
- 手机无法打印log信息
- Okhttp设置请求日志过滤器,支持打印Post请求参数
- 封装OKHttp 拦截器 异常捕获 打印log日志
- python打印log调试信息的方法
- android ndk 入门之打印log信息
- Android c/c++层打印log信息
- mtk android lcm 打印log信息方法
- mtk android lcm 打印log信息方法
- HDU
- 计算机网络 滑动窗口协议
- 静态查找(顺序查找和折半查找)
- 一维数组排序
- K-means和PAM聚类算法Python实现及对比
- 打印okhttp请求log信息
- 登录注册使用数据库
- 视频编码中常用熵编码介绍
- 【Struts】接收表单传递给Action的参数
- 欢迎使用CSDN-markdown编辑器
- 【STM32】一些基础的操作
- java.util.concurrent的线程池
- 为什么说ArrayList是线程不安全的?
- XBanner的简单使用