React-在Fiddler中查看时获取帖子的内容类型正在更改

Pue*_*rto 5 javascript fiddler cors reactjs fetch-api

我在请求类型似乎正在更改的地方抓到我的帖子。我提交基本表格(仅一个字段)。这是提取。

      handleSubmit(event, data) {
    //alert('A name was submitted: ' + this.state.value);
    event.preventDefault();
    console.log("SUBMIT STATE::", this.state.value);
    return (
        fetch("//localhost:5000/api/values/dui/", {
            method: "post",
            mode: 'no-cors',
            headers: {
                'Access-Control-Allow-Origin': '*',
                'Content-Type': 'application/json',
                'Accept': 'application/json',                  
            },
            body: JSON.stringify({
                name: this.state.value,
            })
        }).then(response => {
            if (response.status >= 400) {
                this.setState({
                    value: 'no greeting - status > 400'
                });
                throw new Error('no greeting - throw');
            }
            return response.text()
        }).then(data => {
            var myData = JSON.parse(data);
            this.setState({
                greeting: myData.name,
                path: myData.link
            });
        }).catch(() => {
            this.setState({
                value: 'no greeting - cb catch'
            })
        })
    );


}
Run Code Online (Sandbox Code Playgroud)

但是当我在提琴手中查看时,content-type现在是“ content-type:text / plain; charset = UTF-8”。这是原始的提琴手:

POST http://localhost:5000/api/values/dui/ HTTP/1.1
Host: localhost:5000
Connection: keep-alive
Content-Length: 16
accept: application/json
Origin: http://evil.com/
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Run Code Online (Sandbox Code Playgroud)

内容类型:文本/纯文本;字符集= UTF-8引用者:http:// localhost:3000 / 接受编码:gzip,deflate,br接受语言:zh-cn,en; q = 0.8

{"name":"molly"}
Run Code Online (Sandbox Code Playgroud)

在DOM Inspector中,我只看到:

POST http:// localhost:5000 / api / values / dui / 415(不受支持的媒体类型)

我还发现“接受”既是小写又是“内容类型”,这很奇怪。发生这种情况的任何原因。我尚未在搜索中找到任何具体内容。

sid*_*ker 5

no-cors为请求设置 mode 时,浏览器将不允许您设置除CORS-safelisted request-headers之外的任何请求标。请参阅有关添加标头的规范要求

要将名称/值 ( name / value ) 对附加到Headers对象 ( headers ),请运行以下步骤:

  1. 否则,如果guard是 " request-no-cors" 并且name / value不是CORS-safelisted request-header,则返回。

在该算法中,return等同于“返回而不将该标头添加到 Headers 对象”。

而是将其设置为的原因text/plain;charset=UTF-8是因为请求构造函数的算法调用了包含以下步骤的提取体算法

打开object的类型:

? USV字符串

  • 设置Content-Typetext/plain;charset=UTF-8