axios.get('http://localhost:8080/omp/patients', { headers: {authorization: 'Bearer ' + token}})
.then( response => {
this.state = response.data;
}
).catch(ex=> {
alert("You are not registered");
//console.log(e)
});
在网络中,我有字段:“Access-Control-Request-Headers:授权”,但没有字段“授权: token ”
最佳答案
您需要正确设置 Authorization header ,如上面的评论中所示。
关于 CORS 政策的回复:
您将需要了解 CORS,但本质上,Chrome 和其他浏览器如果在响应时没有设置正确的 CORS header ,则会停止网络请求。预检是在发送实际请求之前发送到同一 URL 以了解该 URL 是否支持 CORS 的初始请求。看起来服务器不理解 CORS 预检或配置不正确。
你有几个选择:
关于reactjs - 我无法执行来自 ReactJS 的请求。 header 无法正确写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58720831/