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) async {
logPrint('*** Request ***');
_printKV('uri', options.uri);
//options.headers;
if (request) {
_printKV('method', options.method);
_printKV('responseType', options.responseType.toString());
_printKV('followRedirects', options.followRedirects);
_printKV('connectTimeout', options.connectTimeout);
_printKV('sendTimeout', options.sendTimeout);
_printKV('receiveTimeout', options.receiveTimeout);
_printKV(
'receiveDataWhenStatusError', options.receiveDataWhenStatusError);
_printKV('extra', options.extra);
}
if (requestHeader) {
logPrint('headers:');
options.headers.forEach((key, v) => _printKV(' $key', v));
}
if (requestBody) {
logPrint('data:');
_printAll(options.data);
}
logPrint('');
handler.next(options);
}