post method

Future<void> post({
  1. required CancelToken cancelToken,
})

发起get请求 cancelToken 取消请求的cancelToken

Implementation

Future<void> post({
  required CancelToken cancelToken,
}) async {
  Options requestOptions = Options();
  Map<String, dynamic>? _authorization = getAuthorizationHeader();
  if (_authorization != null) {
    requestOptions = requestOptions.copyWith(headers: _authorization);
  }
  var url = path;
  assert(url.isNotEmpty, 'url 不能为空');
  try {
    var response = await dio.post(
      url,
      data: params,
      options: requestOptions,
      cancelToken: cancelToken,
    );
    success(response.data);
  } on DioError catch (e) {
    // error统一处理
    AppException appException = AppException.create(e, 1);
    // 错误提示
    debugPrint('DioError===: ${appException.toString()}');
    error(appException.getMessage());
  }
}