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…
Advertisement
Answer
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
when using php the following snippet can be used:
header('Access-Control-Allow-Headers: X-Requested-With, privatekey');