onRequest method
The callback will be executed before the request is initiated.
If you want to continue the request, call handler.next
.
If you want to complete the request with some custom data,
you can resolve a Response object with handler.resolve
.
If you want to complete the request with an error message,
you can reject a DioError object with handler.reject
.
Implementation
@override
Future onRequest(
RequestOptions options, RequestInterceptorHandler handler) async {
if (_checkIgnore(options)) {
handler.next(options);
return;
}
var _networkLog = _NetworkLog("onRequest");
_networkLog.printTopLine();
_networkLog.printLog('*** Request ***');
printKV('uri', options.uri, _networkLog);
_networkLog.printMiddleLine();
if (request) {
printKV('method', options.method, _networkLog);
printKV('responseType', options.responseType.toString(), _networkLog);
printKV('followRedirects', options.followRedirects, _networkLog);
printKV('connectTimeout', options.connectTimeout, _networkLog);
printKV('receiveTimeout', options.receiveTimeout, _networkLog);
printKV('extra', options.extra, _networkLog);
}
//请求 头部 打印
if (requestHeader) {
_networkLog.printMiddleLine();
_networkLog.printLog('headers:');
_networkLog.printLog(options.headers);
}
//请求 参数 打印
if (requestBody) {
_networkLog.printMiddleLine();
_networkLog.printLog('data:');
_networkLog.printLog(options.data);
}
_networkLog.printBottomLine();
handler.next(options);
}