如何修复本地主机的cors错误? [英] How to Fix react cors error in localhost?
问题描述
我正在开发一个React应用.我在哪里请求AXIOS的API.但是,当我运行NPM START在本地主机上测试我的应用程序时,出现CORS错误.这是错误 从来源"通过https://********.com/trx_status.php访问XMLHttpRequest http://localhost:3000 "已被CORS策略阻止:飞行前响应中Access-Control-Allow-Headers不允许使用请求标头字段私钥.
I'm working on a react app. Where I'm requesting for an API by AXIOS. But When I run NPM START to test my app in localhost I'm getting CORS error. Here is the error Access to XMLHttpRequest at 'https://********.com/trx_status.php' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field privatekey is not allowed by Access-Control-Allow-Headers in preflight response.
我是新来的人.请告诉我如何解决这个问题.谢谢...
I'm new in react. Please tell me how can I solve this issue. Thank you...
推荐答案
该错误是由发送到服务器的自定义privatekey
标头引起的.该字段必须包含在服务器的Access-Control-Allow-Headers
响应标头中.可以使用:
The error is caused by the custom privatekey
header that is send to the server. This field has to be included in the Access-Control-Allow-Headers
response header from the server. It can be done using:
Access-Control-Allow-Headers: privatekey
使用php时,可以使用以下代码段:
when using php the following snippet can be used:
header('Access-Control-Allow-Headers: X-Requested-With, privatekey');
这篇关于如何修复本地主机的cors错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!