我使用dio.post作为付款方式API在Postman上运行良好

我使用 dio.post 作为付款方式API 在 Postman 上运行良好,但收到响应时不是 JSON 类型然后应用程序无法处理对可用数据的响应

主要问题是支付成功但是给用户一个错误this is the response.data

我的 Dio 初始化为

  static init() {
  _dio = Dio(
    BaseOptions(
      baseUrl: baseUrl,
      receiveDataWhenStatusError: true,
      followRedirects: false,
      validateStatus: (status) {
      return status! 
      },
    connectTimeout: 60 * 1000 ,
    // 60 seconds
    receiveTimeout: 60 * 1000 ,
    ),
  );
}

我的方法是发布

static Future postData({
required String endPoint,
required dynamic data,
String? token,
 }) async {
// set headers here
_dio.options.headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer $token',

};
return await _dio.post(endPoint, data: data);
}

我这样发送请求

String _fileName = counterImage.path.split('/').last;
        var _image = await MultipartFile.fromFile(
          counterImage.path,
          filename: _fileName,

          contentType: MediaType('image', 'png'),
        );
        FormData _data = FormData.fromMap({
          'my_wallet': mainWallet.id,
          'amount': amount,
          'product': product.id,
          'units_count': unitsCount,
          'image': _image,
        });

        await DioHelper.postData(
          endPoint: '$paymentEndPoint/$subWalletID',
          token: payToken,
          data: _data,
        ).then((value) {
          if (kDebugMode) {
            print('Pay done response ${value.data}');
          }
       

© 版权声明
THE END
喜欢就支持一下吧
点赞120赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容