1

I am trying to read an xml file on web server with axios api call. If I copy the xml file URL on a web browser, it opens xml contents. But if I use axio.get to call that URL, I get "Network Error", "CORS Missing Allow Origin". Below is my code:

const url="https://mydomain/folder/myxmlfile.xml";
await axios
  .get(url, {
    withCredentials: false,
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS",
      "Content-Type": "application/xml; charset=utf-8",
    },
  })
  .then((response) => console.log(response.data))
  .catch((err) => console.log(err));

What am I missing here? Please advise! Thanks.

user788448
  • 779
  • 1
  • 14
  • 36
  • Is there an error on your server side with how your accepting headers in app.use (express)? https://stackoverflow.com/a/18311469/6388582 – IWI Nov 07 '21 at 14:09
  • Error: Network Error Error: Network Error createError createError.js:16 handleError xhr.js:117 dispatchXhrRequest xhr.js:114 xhrAdapter xhr.js:15 dispatchRequest dispatchRequest.js:58 request Axios.js:108 method Axios.js:129 wrap bind.js:9 .... I don't understand these. I have no problem to call API URL in other reactjs app. But this xml file gives me the error. – user788448 Nov 07 '21 at 18:38

0 Answers0