javascriptreactjsaxioscors

response status code 200 but cors error in react js axios


I am trying to hit a open source API from https://citizenatlas.dc.gov/newwebservices/locationverifier.asmx/findLocation2 using axios. My code is:

let fetchDCWardUrl = 'https://citizenatlas.dc.gov/newwebservices/locationverifier.asmx/findLocation2?str=2%252015th%2520St%2520NW,%2520Washington,%2520DC%252020024,%2520USA&f=json';

await axios.get(fetchDCWardUrl).then((response) => {
      console.log(response);
    });

And I am getting: enter image description here enter image description here When I hit the same URL from the postman or directly hit the browser URL bar, I get a response without any error. I also tried using the post method, tried js fetch.


Solution

  • Cors must be enabled on server-side. For development purposes you can use react proxy settins but on production server you must correctly setup your server to create proxy for this request