dio_ext
基于Dio的功能擴(kuò)展,比如攔截器、簡易客戶端等。
配置
//在工程的yaml文件中添加一下依賴
dependencies:
dio_interceptors: ^0.0.1
使用
攔截器(Interceptors)
日志攔截器
dio.interceptors.add(new DioLogInterceptor());
在自己的dio實(shí)例中配置以上語句即可使用。
類似原生Android開發(fā)中使用okhttp3
的logging-interceptor
.
下面是請(qǐng)求http://www.baidu.com輸出的日志效果:
Http: --> GET https://www.baidu.com/wd=sdsdf
Http: Headers:{content-type: application/json; charset=utf-8}
Http: --> END GET
Http: <-- 200 OK https://www.baidu.com/wd=sdsdf (649ms)
Http:{the response:Omitted because there is too much content}
Http: <-- END HTTP
以下是對(duì)標(biāo)記的完整說明:
其中Http是日志標(biāo)簽,默認(rèn)為Http,如果需要修改,創(chuàng)建DioLogInterceptor時(shí)指定參數(shù)即可。
-->:表示發(fā)起請(qǐng)求。
GET:請(qǐng)求方式
Header:請(qǐng)求的Header內(nèi)容。
END GET:請(qǐng)求日志輸出完成的標(biāo)志。
<--:表示相應(yīng)
200: 是請(qǐng)求的響應(yīng)碼,即http status code。
OK:是本次請(qǐng)求結(jié)果的一個(gè)文本描述
(649ms):括號(hào)中是計(jì)算的請(qǐng)求響應(yīng)時(shí)間。
{the response:Omitted because there is too much content}:響應(yīng)的body內(nèi)容,由于內(nèi)容太多,示例中沒有輸出具體內(nèi)容
<-- END HTTP: 響應(yīng)日志輸出完成的標(biāo)志。
更多功能后續(xù)更新。