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
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
var requestUrl = options.baseUrl + options.path;
var urlAndInfo = requestUrl.xSplit('?');
Map<String, dynamic> showInfo = {
'method': '###${options.method}###',
'path': urlAndInfo[0],
};
if (urlAndInfo.length > 1) {
showInfo['info'] = urlAndInfo[1];
}
showInfo['Header信息'] = options.headers;
if (options.queryParameters.isNotEmpty) {
showInfo['query'] = options.queryParameters;
}
if (options.data != null) {
showInfo['data'] = options.data;
}
if (showLog) XLog.i(showInfo);
return handler.next(options);
}