【问题标题】:angular : Origin http://localhost not found in Access-Control-Allow-Origin header角度:在 Access-Control-Allow-Origin 标头中找不到来源 http://localhost
【发布时间】:2016-08-06 16:37:29
【问题描述】:

我正在使用 angularjs Web 应用程序中的以下代码在不同域上调用 REST API,但我在控制台中看到以下错误。非常感谢这里的任何帮助,因为这严重延迟了我的交付。

错误: 在 Access-Control-Allow-Origin 标头中找不到来源 http://localhost

XMLHttpRequest:网络错误 0x80070005,访问被拒绝。

代码:

$http.defaults.headers.post["Content-Type"] = 'application/x-www-form-urlencoded';

        $http.post(this.urlBase + '/Product/PullBasket/', $httpParamSerializerJQLike(cart)).then(function success(result) {         
            if (result.status == 200) {
                Logger.info("Pull Request Id : " + result.data);
            }
            else {
                Logger.info("Error is pull request : " + result.data);
            }
        }, function failure(result) {
            Logger.fatalException("Error is pull request.");
        });

【问题讨论】:

  • 那么 url base 与地址栏中的地址有何不同?
  • urlbase 是从配置文件中提取的其余服务的 url。其余服务托管在不同的服务器上。
  • 所以错误是正确的,它是跨域调用。
  • 是的,我知道它抛出了正确的错误 :) 我正在寻找一些解决步骤。
  • 因此您需要在 api 上启用 CORS,如错误和以下状态的答案。

标签: javascript angularjs cors


【解决方案1】:

很奇怪,但似乎与https://en.wikipedia.org/wiki/Same-origin_policy有关

如果是这样,您必须设置http://enable-cors.org/

【讨论】:

    猜你喜欢
    • 2017-08-24
    • 2013-04-09
    • 2012-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-12
    • 2014-07-14
    相关资源
    最近更新 更多