0

I'm trying to do a get call with axios from my react application. But I keep getting the following error

Access to XMLHttpRequest at 'http://localhost:8080/api/v1/company/getmycompany?uid=1' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

When I do the same call in postman with the same parameters it returns the information with no issue. But I just can't find what is wrong with my code, below my code

const res = await axios.get('http://localhost:8080/api/v1/company/getmycompany?uid=1', {
        headers: {
            'Authorization': 'Bearer  '+ JWTToken
        }
    });

Does anybody know what I'm doing wrong with this?

stevedc
  • 483
  • 3
  • 8
  • 26
  • Does this help: https://stackoverflow.com/questions/18642828/origin-origin-is-not-allowed-by-access-control-allow-origin ? – Ben Stephens Mar 08 '23 at 09:39
  • Yes that helped only I'm missing why postman works and the react app not – stevedc Mar 08 '23 at 09:44
  • Postman is not doing a cross origin request. – Ben Stephens Mar 08 '23 at 09:54
  • My previous comment is kind of wrong (as I think you could set the Origin header in the Postman request and nothing would break), but this might help: https://stackoverflow.com/questions/36250615/cors-with-postman – Ben Stephens Mar 08 '23 at 10:29

0 Answers0