我有一个 AngularJS 应用程序,我需要将数据发布到第三方 URL,该 URL 用于在第三方服务器上存储一些数据。当我运行下面的代码时出现以下错误: XMLHttpRequest cannot load http://thirdparty.url.com/ 。对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问源“ http://localhost:51491 ”。
我在 AngularJS 工厂中运行的代码是:
return $http({
url: '//thirdparty.url.com',
method: "POST",
data: params_string,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, PUT',
'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept'
}
});
原文由 CaptainMorgan 发布,翻译遵循 CC BY-SA 4.0 许可协议
这意味着您的 http://thirdparty.url.com/ 不接受来自/不是来自 http://thirdparty.url.com/ 的外部来源的请求,因此您必须从您的 thirdparty.url 启用它。 com