DioError [DioErrorType.RESPONSE]:Http 状态错误 [405]

2024-04-24

我正在创建一个post请求使用Dio https://pub.dev/packages/dio, 这是我的FormData params,

    FormData formData = FormData.fromMap({
      'wallet_id': '${dropdownValue.walletId}',
      'member_id': '${_loginModel.memberId}',
      'draw_amount': withdrawalAmountContoller.text,
      'login_password': passwordController.text,
    });

然后我就过去了params像这样,

Response response = await dio.post(url, data: params);

但我在请求时收到错误,

错误 [DioError [DioErrorType.RESPONSE]:Http 状态错误 [405]] => 路径:https://vertoindiapay.com/pay/api/withdraw https://vertoindiapay.com/pay/api/withdraw

E/flutter(6703):[错误:flutter/lib/ui/ui_dart_state.cc(157)]未处理的异常:DioError [DioErrorType.RESPONSE]:Http 状态错误 [405]

E/flutter(6703):#0 DioMixin._request._errorInterceptorWrapper。 (包:dio/src/dio.dart:848:13)

请帮我解决这个问题。我的网址是=>https://vertoindiapay.com/pay/api/withdraw https://vertoindiapay.com/pay/api/withdraw


虽然这在邮递员中工作得很好,


  Future<void> signUpUser() async {
    final formData = {
      'username': 'test1',
      'password': 'abcdefg',
      'grant_type': 'password',
    };
 try {
    Dio _dio = new Dio();
    _dio.options.contentType = Headers.formUrlEncodedContentType;

    final responseData = await _dio.post<Map<String, dynamic>>('/token',
        options: RequestOptions(
           
            method: 'POST',
            headers: <String, dynamic>{},
            baseUrl: 'http://52.66.71.229/'),
        data: formData);

   
      print(responseData.toString());
    } catch (e) {
      final errorMessage = DioExceptions.fromDioError(e).toString();
      print(errorMessage);
    }

  }



 class DioExceptions implements Exception {
  
  DioExceptions.fromDioError(DioError dioError) {
    switch (dioError.type) {
      case DioErrorType.CANCEL:
        message = "Request to API server was cancelled";
        break;
      case DioErrorType.CONNECT_TIMEOUT:
        message = "Connection timeout with API server";
        break;
      case DioErrorType.DEFAULT:
        message = "Connection to API server failed due to internet connection";
        break;
      case DioErrorType.RECEIVE_TIMEOUT:
        message = "Receive timeout in connection with API server";
        break;
      case DioErrorType.RESPONSE:
        message =
            _handleError(dioError.response.statusCode, dioError.response.data);
        break;
      case DioErrorType.SEND_TIMEOUT:
        message = "Send timeout in connection with API server";
        break;
      default:
        message = "Something went wrong";
        break;
    }
  }

  String message;

  String _handleError(int statusCode, dynamic error) {
    switch (statusCode) {
      case 400:
        return 'Bad request';
      case 404:
        return error["message"];
      case 500:
        return 'Internal server error';
      default:
        return 'Oops something went wrong';
    }
  }

  @override
  String toString() => message;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

DioError [DioErrorType.RESPONSE]:Http 状态错误 [405] 的相关文章

随机推荐