我的rest api工作成功。当我用Dio发送请求时。服务总是返回500内部服务器错误。头
post请求
戴奥选项创建表单数据
var formData = FormData.fromMap({
'user': 'username',
'pass': 'password',
});
response = await dio.post('apiendpoint', data: formData);
我认为你在标题中缺少内容类型。根据您的远程接受'application/x-www-form-urlencoded'
或'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);
}
你可以这样尝试:
var formData = {
'user': 'username',
'pass': 'password',
};
response = await dio.post('apiendpoint', data: jsonEncode(formData));