【发布时间】:2019-01-23 03:37:33
【问题描述】:
从 ReactJS 应用发送请求:
fetch(http://my-api-domain, {
method: 'GET',
mode: 'cors', //tried no-cors and same-origin
headers: {
'X-Auth-Token': auth_token' // custom-header
}
}).then(response => console.log(response))
.then(data => {
console.log(data);
}
});
package.json 文件有"proxy": "http://my-api-domain/"
然后我在浏览器(firefox)上遇到此错误:
- Cross-Origin Request Blocked: (Reason: missing token ‘x-auth-token’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel).
- Cross-Origin Request Blocked: (Reason: missing token ‘access-control-allow-headers’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel).
- Cross-Origin Request Blocked: (Reason: CORS request did not succeed).
PS:API 服务器配置没问题。我已经在 Postman 上测试了我的 API。发送带有标头key: X-Auth-Token; value: [token] 的GET 请求。工作正常。
【问题讨论】: