Home > Enterprise >  Api is working in postman but response always return 500 in flutter
Api is working in postman but response always return 500 in flutter

Time:07-03

My rest api is working successfully. When I send post request in flutter with Dio. Service always return 500 internal server error. header

post request

Dio Options

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);
}
  • Related