0

I have been using axios in react. Since I made a cross domain request. I have been facing this issue. Although i have gone through all the solutions by adding headers.

await axios.get(`http://abc.in`,{headers: { 'Access-Control-Allow-Origin': '*', }});.

Also added proxy in my package.json "proxy":"http://abc.in"

  • You can set up a [proxy](https://create-react-app.dev/docs/proxying-api-requests-in-development/) for dev environment. – HMR Apr 10 '20 at 09:03

1 Answers1

0

The Access-Control-Allow-Origin header is sent by the server as response header (whereas you are sending it in the request and this will have no effect) to tell the browser that the content of this page is accessible to certain origins (in this case the asterisk means all origins). If the server you are making a request to doesn't allow cross-origin requests, or it does but your domain is not in the list of accepted domains, you will not be able to access it.

An detailed explaination of how this works is here: How does Access-Control-Allow-Origin header work?

Richard Lovell
  • 848
  • 10
  • 18