首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Angular JS Cors请求的资源错误上没有'Access-Control-Allow-Origin‘标头

Angular JS Cors请求的资源错误上没有'Access-Control-Allow-Origin‘标头
EN

Stack Overflow用户
提问于 2015-12-15 01:20:09
回答 1查看 945关注 0票数 0

在我的C# web api上,我启用了cors,即

代码语言:javascript
运行
复制
[EnableCors(origins: "*", headers: "*", methods: "*")]

然后在我的angular js站点中,我调用post API。

代码语言:javascript
运行
复制
authService.login = function (credentials) {
                return $http
                    .post(WEB_CONFIG.login, credentials)
                    .then(function (res) {
                        Session.create(res.data.Email, res.data.Roles,res.data.Username);
                        return res.data.user;
                    });
            };

angular站点发出来自localhost:9000的请求,而API位于localhost

获取错误

XMLHttpRequest无法加载http://localhost/mysite/api/user/login。对印前检查请求的响应未通过访问控制检查:请求的资源上不存在“access - control -Allow-Origin”标头。因此不允许访问源'http://localhost:9000‘。

为什么在启用Cors的情况下会出现此错误?

EN

回答 1

Stack Overflow用户

发布于 2017-07-25 02:59:06

尝试此配置。

代码语言:javascript
运行
复制
cors:
    allowed-origins: "*"
    allowed-methods: GET, PUT, POST, DELETE, OPTIONS
    allowed-headers: "*"
    exposed-headers:
    allow-credentials: true
    max-age: 1800
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34272946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档