1

I was giving an api to connect to react and I tested the api with posting man it was working fine but when I send post using axios in react I get cors error

How do I resolve this issue

  const handleSubmit = (e) => {
    e.preventDefault();
   axios.get("https://etsea.herokuapp.com/category/", {
      "Content-Type": "application/json"
      } 
    )
    .then(res => {
      console.log(res.data);
    })
    .catch(err => {
      console.log(err)
    })

} The backend was developed with python.

I tried removing the trailing slash but it does not work if the trailing slash is removed both in postman or in react

etranz
  • 891
  • 2
  • 10
  • 29
  • 1
    Does this answer your question? [Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-code-receive-a-no-access-control-allow-origin-header-i) – DCTID Aug 02 '21 at 23:47

1 Answers1

0

If you are getting a CORS error, then that generally means that you cannot send the request from the browser. The service receiving the request is blocking it, usually due to security concerns.

You need to send a same origin request, which is done server side. In this case, it would be sent from your Python server, and not from your client-side ReactJS.

adlopez15
  • 3,449
  • 2
  • 14
  • 19