I am trying to send a GET request to a back-end server with some parameters, and I have been getting the error:
DioError [DioErrorType.RESPONSE]: Http status error [500]
The parameters I am sending contains a boolean value and a double too. How can I successfully make this request. I have tried so many answers on Stack Overflow but none worked for me. Below is my code snippet:
Future<Converter> currencyConverter() async {
String convertURL = baseURL + 'convert/currency/';
String auth = await localpref.getString('access');
// FormData formData = new FormData.fromMap({
// "switch": _switch,
// "s_currency": senderCurrencyVal,
// "r_currency": recieverCurrencyVal,
// "amount": amount
// });
Map<String, dynamic> payload = {
"switch": _switch, //boool
"s_currency": senderCurrencyVal, // string
"r_currency": recieverCurrencyVal, // string
"amount": amount //double
};
try {
var res = await dio.get(
convertURL,
//data: formData,
queryParameters: payload,
options: Options(
followRedirects: false,
validateStatus: (status) {
return status < 500;
},
headers: {
"accept": "*/*",
"Authorization": "Bearer $auth",
"Content-Type": "application/x-www-form-urlencoded"
}
)
);
if (res.statusCode >= 200 && res.statusCode <= 250) {
print("Transfer Succeed");
var respBody = res.data;
Converter converter = converterFromJson(res.data);
print(converter.result);
return converter;
} else {
print(res);
print("Else not successful");
}
} catch (e) {
print(e);
}
}
Note: that am not in charge of the backend and I am made to know it was developed with Djangom also I have tried both dio.get and dio.request but I got the same result, formdata doesn't work with GET when using Dio.
This request works well in postman.
I would appreciate your help.