【发布时间】:2018-04-14 22:44:12
【问题描述】:
我有以下 angularjs 代码:
this.createAccount = function (payload) {
var parameters = {
grant_type: 'password',
client_id: clientId,
client_secret: clientSecret,
email: payload.Email,
password: payload.Password,
scope: 'myApi offline_access openid'
}
return $http({
method: "POST",
url: $sce.trustAsResourceUrl(identityApiURL + '/account/register'),
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json'
},
data: 'grant_type=' + parameters.grant_type + '&client_id=' + parameters.client_id + '&client_secret=' + parameters.client_secret + '&email=' + encodeURIComponent(parameters.email) + '&password=' + parameters.password + '&scope=' + parameters.scope
}).error(function (response) {
$log.error('Something went wrong when creating your account', response);
});
}
在尝试运行它时,我不断在控制台中收到以下错误:
无法加载https://........account/register:对预检请求的响应未通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。 Origin 'https://localhost:3000' 因此不允许访问。
我可以看到正在使用我的参数创建一个配置对象,但数据为 NULL。 同样在网络上,我看到了 OPTIONS,但没有触发 POST 方法...
怎么了?
提前致谢!
【问题讨论】:
-
我确信它确实如此......我正在为登录做另一篇文章,它很好......
-
错误清楚地表明您的服务器没有响应预检请求重新检查如何在服务器上启用预检