【问题标题】:"Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource."“跨源请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource。”
【发布时间】:2016-07-27 09:06:33
【问题描述】:

我正在从 localhost:8000 提供一个 Angular 应用程序,并从 localhost:3000 提供一个节点后端。我在页面加载和前端日志中运行了一个 $http.get

Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

有多个关于此的 SO 帖子,但他们都说“不要直接在浏览器中打开您的文件”,我正在为它们提供服务,而不是打开它们。

我的后端为 CORS 配置,并且通过 Postman 访问它们时路由工作。

前端:

后端:

错误:

host + '/' 只是一个引用“localhost:3000”的常量

【问题讨论】:

    标签: angularjs node.js cors


    【解决方案1】:

    您的网址缺少方案 (http:)。您正在尝试使用相对 URL,该 URL 解析为 file:///blah/blah/blah/localhost:3000 之类的东西......并且正如错误消息所述,您无法从 file: URL 加载数据,因为那里不支持 CORS。使用正确的网址。

    【讨论】:

      猜你喜欢
      • 2015-12-11
      • 2017-10-11
      • 2017-12-25
      • 2018-04-16
      • 2020-07-02
      • 1970-01-01
      • 1970-01-01
      • 2014-12-30
      相关资源
      最近更新 更多