未处理的异常:第 1 行第 10 列错误:无效的媒体类型:应为“/”。使用 flutter http

Unhandled Exception: Error on line 1, column 10: Invalid media type: expected "/". using flutter http

我正在尝试使用 The flutter HTTP package

在我的 flutter 应用程序中发送 Http post 请求

这是代码:

String url = 'http://my_website.com/api/panel/attendance/create';
Response response = await post(url, headers: {
  "Authorization": "Basic My_basic_auth",
  "content-type": "form-data",
}, body: {
  "username": username,
  "employee_id": employee_id,
  "latitude": latitude,
  "longitude": longitude,
  "type": type,
});

我收到了这条奇怪的错误消息:

Unhandled Exception: Error on line 1, column 10: Invalid media type: expected "/".

我认为这是编码或其他东西,我不确定。

尝试使用 -

var response = await http.post(url, body);

而不是响应 response = await post(url, body);

如果还是不行,请提供更多数据,我可以解决错误。

调用 client = https.client() 并使用 client 调用解决了问题