我正在开发一个flutter项目,在api上我遇到了一个问题。它在postman中可以正常工作,但在flutter中给出post方法错误。 请帮助我,我已经使用了可能的解决方案。
代码:
var body = jsonEncode({
"userid": "2",
"CUSTOMERID":"158",
"OFFSET":"0"
});
final response = await http.post(
"http://18.191.223.160/webservices/FoodSubCategoryList",
headers: {
"Accept": "application/json",
"Tokenvalue": "sOzz0Y6O",
"Content-Type": "application/json"
}, body: body
);
邮递员:-
答案 0 :(得分:0)
尝试
http.Response response = await http.post("http://18.191.223.160/webservices/FoodSubCategoryList",
body: { "userid": "2",
"CUSTOMERID":"158",
"OFFSET":"0"},
headers: {
"Accept": "application/json",
"Tokenvalue": "sOzz0Y6O",
"Content-Type": "application/json"
});
var responseJson = json.decode(response.body);
代替此
var body = jsonEncode({
"userid": "2",
"CUSTOMERID":"158",
"OFFSET":"0"
});
final response = await http.post(
"http://18.191.223.160/webservices/FoodSubCategoryList",
headers: {
"Accept": "application/json",
"Tokenvalue": "sOzz0Y6O",
"Content-Type": "application/json"
}, body: body
);
我希望对您有帮助
答案 1 :(得分:0)
更新依赖项http:^ 0.12.1