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<void> onRequest(
RequestOptions options, RequestInterceptorHandler handler) async {
_startTime = DateTime.now();
log('----------Start----------');
if (options.queryParameters.isEmpty) {
log('RequestUrl: ' + options.baseUrl + options.path);
} else {
log('RequestUrl: ' +
options.baseUrl +
options.path +
'?' +
Transformer.urlEncodeMap(options.queryParameters));
}
log('RequestMethod: ' + options.method);
log('RequestHeaders:' + options.headers.toString());
log('RequestContentType: ${options.contentType}');
log('RequestData: ${options.data.toString()}');
super.onRequest(options, handler);
}