AngularJS没有'Access-Control-Allow-Origin'标头 [英] AngularJS No 'Access-Control-Allow-Origin' header
问题描述
我有一个AngularJS应用,我需要将数据发布到第三方URL,该URL用于在第三方服务器上存储一些数据.当我在下面运行我的代码时,出现以下错误: XMLHttpRequest无法加载 http://thirdparty.url.com/.对预检请求的响应未通过访问控制检查:在所请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许访问来源' http://localhost:51491 .
I have an AngularJS app that I need to post data to a third party URL which is used to store some data on the third party server. I get the following error when I run my code below: XMLHttpRequest cannot load http://thirdparty.url.com/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:51491' is therefore not allowed access.
我在AngularJS工厂中运行的代码是:
The code I'm running in my AngularJS factory is:
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'
}
});
推荐答案
这意味着您的 http://thirdparty.url .com/ 不接受来自 http://thirdparty.url.com/的外部来源的请求,因此,您必须从您的thirdparty.url.com
This means that your http://thirdparty.url.com/ Does not accept requests from external sources that is/are not from http://thirdparty.url.com/, so you have to enable it from your thirdparty.url.com
这篇关于AngularJS没有'Access-Control-Allow-Origin'标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!