【发布时间】:2021-11-20 15:45:08
【问题描述】:
我正在尝试使用 http 包获取 api。它正在使用邮递员。它在正文中有表单数据。我无法弄清楚我们如何在标题中调用表单数据。我会附上邮递员的图片以便更好地理解。
我的代码:
Future<LocationDetailsById> locationDetailsByID(BuildContext context,String locationID) async{
String url = baseUrl + "location/detailsbyid";
var body = {
"location_id":int.parse(locationID)};
Utils.showLoaderDialog(context);
final response = await http.post(Uri.parse(url), headers: {
'Accept': 'application/json',
'Content-Type': 'application/form-data',
'Authorization':'Bearer ${Utils.token}',
}, body: jsonEncode(body)
);
print("request $locationID");
print("response ${response.body}");
if(response.statusCode == 200){
Navigator.pop(context);
return LocationDetailsById.fromJson(json.decode(response.body));
}else {
return Utils.errorDialog(context, "Something went wrong");
}
}
【问题讨论】: