无法使用fetch设置标头

时间:2017-09-18 11:52:25

标签: react-native fetch fetch-api

我设置了一个标题,用于使用application / x-www-form-urlencoded表单正文发布请求; 这是我的代码

var headers = new Headers();
      headers.append('Content-Type','application/x-www-form-urlencoded');

      fetch(url, {
        method: "POST",
        mode:"cors",
        header:headers,
       body: qs.stringify(params)
    })

但Content-type在请求中自动更改

Content-Type    text/plain;charset=UTF-8

因此我无法正确接收此请求参数。 有谁见过吗?

1 个答案:

答案 0 :(得分:1)

CORS仅允许内容类型的子集。我失去了很多时间。 :)

this answer。尽管在CORS请求中可以application/x-www-form-urlencoded,但我认为通过在mode: 'cors'调用中设置fetch,您的标题很可能会被覆盖。

相关问题