简体   繁体   English

多部分/表单数据内容类型中的 POST JSON (JavaScript)

[英]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.

相关问题 如果我使用 Content-Type multipart/form-data 如何获取“php://input”数据 - How to get “php://input” data if I'm using Content-Type multipart/form-data 为RESTful POST api使用multipart / form-data Content Type是一个好习惯吗? - Does using multipart/form-data Content Type for a RESTful POST api a good practice? 每个边界的PHP curl multipart / data-form content-type - php curl multipart/data-form content-type for each boundary 使用curl rest api发送,具有多个内容类型的多部分数据 - send with curl rest api, multipart data with multiple content-type Pentaho HTTP Post multipart/form-data - Pentaho HTTP Post multipart/form-data 带有ContentType Multipart / form-data的WebException - WebException with ContentType Multipart/form-data 将 Multipart/Form-Data 转换为 JSON - Converting Multipart/Form-Data to JSON 将表单类型更改为multipart / form-data会导致req.body为空 - Changing form type to multipart/form-data causes req.body to be empty 使用curl POST使用multipart / form-data将二进制文件作为JSON参数传递 - Pass binary file as JSON parameter using multipart/form-data using curl POST 将表单数据作为JSON发送 - 浏览器更改内容类型 - Sending form data as JSON - Browser changing Content-Type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM