无法加载资源。 Access-Control-Allow-Origin不允许使用Origin

时间:2018-02-22 08:50:30

标签: ajax reactjs cors axios

我正在使用axios唤醒React应用程序。我将网站推向了生产状态,这个错误"来自Access-Control-Allow-Origin"仍然存在。

如果我使用任何其他浏览器,而不是我在开发中使用的浏览器,那里有" cors"用作chrome扩展的插件。数据根本没有从API加载。

我尝试过在线提供的所有解决方案。但它不起作用。请帮忙!

这是我在控制台中遇到的错误:

[Error] Failed to load resource: Origin https://freektm.com is not allowed by Access-Control-Allow-Origin. (courses, line 0)
[Error] XMLHttpRequest cannot load https://www.remotesite.com/api-2.0/results. Origin https://freektm.com is not allowed by Access-Control-Allow-Origin.

index.js

 const url = 'https://www.remotesite.com/api-2.0/results';    

    axios
              .get(url,config)
              .then(response => response)
              .then(result => this.setSearchResults(result))
              .catch(e => e);

Config.js

export const config = {
  headers: {
    "Content-Type": "application/json",
    Accept: "application/json, text/plain, */*",
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "GET, PUT, POST, DELETE, OPTIONS",
    "Access-Control-Allow-Origin": "http://example.com",
    "Access-Control-Allow-Origin": "http://www.example.com",
    Authorization:
      "Basic " +
      btoa(
        "CLIENTIDDDDDDDDDDDDDD:CLIENTSECRETTTTTTTTTTTTTTTTT"
      )
  }
};

0 个答案:

没有答案