访问被 CORS 政策阻止的“获取”

时间:2021-07-26 15:29:51

标签: javascript api cors odata

我在设计用于获取数据的应用程序时收到以下错误。 “从源 'http://localhost:8080' 获取在 'https://[url here].eu/odata/v2/Candidate?$format=json' 的访问已被 CORS 政策阻止:对预检请求的响应没有通过访问控制检查:它没有 HTTP ok 状态”。

该网站需要用户名和密码才能访问,我已将其包含在代码中,

      //the credentials
      let username = "username";
      let password = "password";

      let response = await fetch(
        "https://[url here].eu/odata/v2/Candidate?$format=json", //The url with which to fetch the data
        {
          method: "GET", 
          headers: {
            Authorization: "Basic " + btoa(username + ":" + password), //our way of encoding the credentials
          },
        }
      );
      let customers = await response.json();
      this.setProperty("/customers", customers.d.results);


And I don't believe that the issue is with the code, I believe it is a CORS policy issue. How do I enable CORS to be able to transfer data in the instance? 

0 个答案:

没有答案