【发布时间】:2017-10-01 11:44:08
【问题描述】:
我正在尝试使用 Angular 2(版本 4.0.0)从开发环境(localhost:4200)调用 REST API
收到以下错误消息: “跨源请求被阻止:同源策略不允许读取位于https://localhost:8000/auth 的远程资源。(原因:CORS 标头‘Access-Control-Allow-Origin’缺失)。”
这里我提供一个代码示例供参考:
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
return this.http.post(this.loginUrl, 'POST_Parameters', {
headers: headers
}).map(res => {
console.log(res);
});
有人可以帮我找出解决这个问题的方法吗?
【问题讨论】: