My rest api is working successfully. When I send post request in flutter with Dio. Service always return 500 internal server error. header
CodePudding user response:
To create a form data use this
var formData = FormData.fromMap({
'user': 'username',
'pass': 'password',
});
response = await dio.post('apiendpoint', data: formData);
CodePudding user response:
I think you are missing the content-type in your header.. based on what your remote accepts either 'application/x-www-form-urlencoded'
or 'application/json'
var data = {"phone": mobileNumber, "password": password};
var dio = Dio();
dio.options.headers['content-Type'] = 'application/x-www-form-urlencoded';
try {
var response = await dio.post(ApiUrl.baseUrl url, data: data);
print(response);
} on DioError catch (e) {
print(e);
}