HttpLoggingInterceptor的用法简介
2017-02-16 14:12
176 查看
该拦截器用于记录应用中的网络请求的信息。
示例
示例
OkHttpClient client = new OkHttpClient(); HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(Level.BASIC); client.interceptors().add(logging); /* 可以通过 setLevel 改变日志级别 共包含四个级别:NONE、BASIC、HEADER、BODY NONE 不记录 BASIC 请求/响应行 --> POST /greeting HTTP/1.1 (3-byte body) <-- HTTP/1.1 200 OK (22ms, 6-byte body) HEADER 请求/响应行 + 头 --> Host: example.com Content-Type: plain/text Content-Length: 3 <-- HTTP/1.1 200 OK (22ms) Content-Type: plain/text Content-Length: 6 BODY 请求/响应行 + 头 + 体 */ // 可以通过实现 Logger 接口更改日志保存位置 HttpLoggingIntercetptor logging = new HttpLoggingInterceptor(new Logger() { @Override public void log(String message) { Timber.tag("okhttp").d(message); } });
相关文章推荐
- HttpLoggingInterceptor的用法简介
- Android HttpLoggingInterceptor的用法简介
- HttpServlet类简介和简单用法
- 简介AngularJS中$http服务的用法
- [翻译]HTTP Modules简介及典型用法
- Chrome浏览器插件Postman用法简介-Http请求模拟工具
- Postman用法简介-Http请求模拟工具
- Postman用法简介-Http请求模拟工具
- Apizza用法简介-Http请求模拟工具
- Apizza用法简介-Http请求模拟工具
- Postman用法简介-Http请求模拟工具
- Postman用法简介-Http请求模拟工具
- Postman用法简介-Http请求模拟工具
- Android 网络框架 HttpLoggingInterceptor优化
- HttpLoggingInterceptor 拦截的log信息为unicode字符时的解决办法
- Postman用法简介-Http请求模拟工具
- Postman用法简介-Http请求模拟工具
- Android的OkHttp包中的HTTP拦截器Interceptor用法示例
- Android的OkHttp包中的HTTP拦截器Interceptor用法示例
- XMLHTTPRequest简介以及用法加个人真实示例