[英]POST JSON in multipart/form-data content type (JavaScript)
I am trying to send an object within a multipart/form-data request, the problem is that no matter what I do, I get this error: 'Content type 'application/octet-stream' not supported'.我正在尝试在 multipart/form-data 请求中发送 object,问题是无论我做什么,我都会收到此错误:“不支持内容类型‘application/octet-stream’”。 It's the same error that I get when I delete the 'application/json' content type from postman. I have tried different solutions that were suggested in similar questions but none of those worked.这与我从 postman 中删除“application/json”内容类型时遇到的错误相同。我尝试了类似问题中建议的不同解决方案,但都没有奏效。
This is how it should be configured in postman to work: postman request这是在 postman 中应该如何配置才能工作: postman 请求
And this is the request that returns the error mentioned above:这是返回上述错误的请求:
const data = JSON.stringify(values);
const formData = new FormData();
formData.append('metadata', data);
return await axios.post(
url,
formData
);
It works for me, try this:它对我有用,试试这个:
const json = JSON.stringify(values);
const dataTemp = new Blob([json], {
type: 'application/json'
});
var formData = new FormData();
formData.append('metadata', dataTemp);
Apologize if it does not work.如果它不起作用,请道歉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.