request<T> method
Future<DioResult<T>>
request<
T>( - String path, {
- DioMethod method = DioMethod.get,
- Map<String, dynamic>? parmas,
- dynamic data,
- CancelToken? cancelToken,
- Options? options,
- Dio? dio,
- ProgressCallback? onSendProgress,
- ProgressCallback? onReceiveProgress,
})
Implementation
Future<DioResult<T>> request<T>(String path,
{DioMethod method = DioMethod.get,
Map<String, dynamic>? parmas,
data,
CancelToken? cancelToken,
Options? options,
Dio? dio,
Map<String, dynamic>? extra = const {'needCache': false},
ProgressCallback? onSendProgress,
ProgressCallback? onReceiveProgress}) async {
const methodValues = {
DioMethod.get: 'get',
DioMethod.post: 'post',
DioMethod.put: 'put',
DioMethod.delete: 'delete',
DioMethod.patch: 'patch',
DioMethod.head: 'head'
};
assert(_dio != null, "请调用init方法初始化网络请求");
options ??= Options(
method: methodValues[method],
contentType: Headers.jsonContentType,
extra: extra);
try {
Response response = await (dio ?? _dio!).request(path,
data: data,
queryParameters: parmas,
cancelToken: cancelToken ?? _cancelToken,
options: options,
onSendProgress: onSendProgress,
onReceiveProgress: onReceiveProgress);
return DioResult(response: response.data);
} on DioException catch (e) {
// debugInfo('请求失败 $e');
return DioResult(e: e);
} catch (e) {
return DioResult(unknown: e);
}
}