Json 颤振发送post请求返回http错误500
我一直在为颤振项目工作,该项目接受用户的姓名和电话号码,但当我保存它时,它显示了500的响应,但从邮递员它的工作良好。 但这里是代码Json 颤振发送post请求返回http错误500,json,flutter,http,Json,Flutter,Http,我一直在为颤振项目工作,该项目接受用户的姓名和电话号码,但当我保存它时,它显示了500的响应,但从邮递员它的工作良好。 但这里是代码 void RegisterUsers(String names, String phone) async{ String urlInser = "https://hmmmiii.com/api/addUser"; Map<String, String> headers = {
void RegisterUsers(String names, String phone) async{
String urlInser = "https://hmmmiii.com/api/addUser";
Map<String, String> headers = {
'Content-Type': 'application/json',
//'Accept': 'application/json',
};
final msg = jsonEncode({"Name":"$names","PhoneNumber":"$phone"});
var response = await http.post(urlInser,
headers: headers,
body: msg);
print(response.statusCode);
if (response.statusCode == 200) {
print('User Registered');
} else {
print('Unsuccessful');
}
void RegisterUsers(字符串名称、字符串电话)异步{
字符串urlInser=”https://hmmmiii.com/api/addUser";
映射头={
“内容类型”:“应用程序/json”,
//“接受”:“应用程序/json”,
};
final msg=jsonEncode({“Name”:“$names”,“PhoneNumber”:“$phone”});
var response=wait http.post(urlInser,
标题:标题,
主体:味精);
打印(响应状态码);
如果(response.statusCode==200){
打印(“用户注册”);
}否则{
打印(“未成功”);
}
其中名称和电话是textController值,谢谢。在postman中,您将请求作为表单数据发送,但在代码中,您将其作为简单的JSON发送 您必须改用
MultipartRequest
最终url='您的url';
final request=http.MultipartRequest('POST',Uri.parse(url))
..字段['Name']='some Name'
..字段['PhoneNumber']='some PhoneNumber';
最终响应=等待请求。发送();
final responseBody=wait response.stream.bytesToString();
打印('RESPONSE BODY:$responseBody');