0

I try to fetch data from URL link in VUE, the link response XML data in the browser but, when I try to retrieve the data in the code I get CORS error:

fetch(
  'https://www.treasury.gov/resource-center/data-chart-center/interest-rates/Datasets/yield.xml',
  {
    method: 'GET',
    headers: {
      'Content-Type': 'text/xml',
    },
  }
)
  .then((response) => {
    console.log(response);
    response.text();
  })
  .then((data) => {
    const parser = new DOMParser();
    const xml = parser.parseFromString(data, 'application/xml');
    console.log(xml);
  })
  .catch(console.error);

This is the error

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • If the target site does not explicitly want to allow access from pages served by different domains, there's nothing you can do other than implement a proxy of your own. – Pointy Mar 07 '21 at 19:25
  • Or use a third party cors proxy service of which there are several – charlietfl Mar 07 '21 at 19:27

0 Answers0