在flutter中在http请求发送时设置"content-type": "application/json"会出现报错Cannot set the body fields of a Request with content-type “application/json”
解决方法
通过jsonEncode处理要提交的参数
final putData = jsonEncode(params); // 处理提交参数
final putResponse = await http.put('http://192.168.201.21/user/modifyUser',
body: putData,
headers: {"token": userBasicsInfo.userTokenResult,"content-type": "application/json"}
).then((response){
var backResult;
if(response.statusCode == 200){
。。。。。。
}else{
print('数据请求错误:${response.statusCode}');
}
return backResult;
});
在Flutter里,HTTP请求发送时设置'content-type': 'application/json'会报错'Cannot set the body fields of a Request with content-type “application/json”',解决办法是通过jsonEncode处理要提交的参数。
3473

被折叠的 条评论
为什么被折叠?



