我不知道如何在我的代码中解决这个问题。我的代码如下:
$http({
method: 'POST',
url: "http://urlexample.com.br",
headers : {
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8;",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers" : "X-Custom-Header",
"Access-Control-Allow-Credentials": true,
"Access-Control-Allow-Methods": "POST",
"Accept" : "application/x-www-form-urlencoded;charset=utf-8;"
},
data: {
"username": login,
"password": senha
}
}).then(function (success) {
callback(success);
}, function (error) {
errorCallback(error);
});
错误是:
“已被CORS策略阻止:对飞行前请求的响应不通过访问控制检查:请求的资源上不存在‘访问控制-允许-原产地’标题。”
谢谢。
发布于 2019-04-01 22:51:01
您将得到此错误,因为您正在调用位于不同域中的API,而这正是CORS (交叉源资源共享)策略所阻止的,除非您允许从其他域访问API。
您可以通过在后端安装一个包来解决这个错误(如果您正在使用laravel),这取决于您正在使用的技术。
看一下这个问题,它们会帮助你理解和解决问题。
AngularJS performs an OPTIONS HTTP request for a cross-origin resource
CORS: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true
https://stackoverflow.com/questions/55462737
复制相似问题