【发布时间】:2015-04-03 02:57:48
【问题描述】:
我已经实现了使用 https://developers.google.com/+/web/signin/server-side-flow 的 AngularJS 应用程序
问题是我的 AngularJS 在一台服务器上,而 Rest Api 在另一台服务器上。当我尝试登录时,一切正常,直到我的回调函数调用 rest api。
这是错误:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://liveboard-dev.locastic.com/api/v1/login. This can be fixed by moving the resource to the same domain or enabling CORS.
服务器没有问题,因为我可以从代码的任何部分调用此方法,除非我在弹出窗口关闭后直接从谷歌发送身份验证响应。
我调用api的angularjs代码是:
$http.post(applicationSettings.authenticationAPIUrl, authResult['code'], {headers: {'Content-Type': 'application/octet-stream; charset=utf-8'}}).success(function (response) {
identityService.setIdentity(response);
deferred.resolve(response);
}).error(function (error) {
deferred.reject(error);
});
【问题讨论】:
-
是的,但我不想构建代理服务器,因为我的服务器应用程序已经是某种代理
-
我的意思是你在 Angular js 上启用了 CORS 吗?
-
@NarekMamikonyan 你是什么意思?
-
我已经发布了喜欢的答案
标签: javascript angularjs api oauth cors