'Flutter Dio response type<!DOCTYPE html> not json
I'm using dio.post for the payment method the API working well on Postman but when receiving the response is not a JSON type It is and then the app can not handle the response to a usable data
the main problem is that the payment don successfully but it gives an error to the userthis is the response.data
My Dio initialized as
static init() {
_dio = Dio(
BaseOptions(
baseUrl: baseUrl,
receiveDataWhenStatusError: true,
followRedirects: false,
validateStatus: (status) {
return status! < 500;
},
connectTimeout: 60 * 1000 ,
// 60 seconds
receiveTimeout: 60 * 1000 ,
),
);
}
My Method is Post
static Future<Response> 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);
}
I send the request as this
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}');
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
