Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 取回http请求所替换的内容类型错误_Javascript_Json_Http_Fetch - Fatal编程技术网

Javascript 取回http请求所替换的内容类型错误

Javascript 取回http请求所替换的内容类型错误,javascript,json,http,fetch,Javascript,Json,Http,Fetch,我在客户端上有以下代码: return fetch('http://localhost:8080/api/authenticate', { method: 'POST', mode: 'no-cors', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username: 'admin', password: '

我在客户端上有以下代码:

return fetch('http://localhost:8080/api/authenticate', {
    method: 'POST',
    mode: 'no-cors',
    headers: {
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        username: 'admin',
        password: 'admin',
    }),
});
当我出于某种原因发送此请求时,内容类型被替换为
text/plain;字符集=UTF-8
。这使得我的服务器端请求失败,因为它只接受
application/json
请求。我做错了什么? 我使用的是Chrome 51,以下是我的要求:

编辑: 当我删除
JSON.strigify()时,
内容类型和请求负载也被省略。 以下是一个例子:


您已经设置了
模式:“无cors”,因此无法将
'Content-Type'
设置为
'application/json'
。它不是。

您已经设置了
模式:'no cors',
,因此您不能将
'Content-Type'
设置为
'application/json'
。这不是最重要的问题之一