【发布时间】:2016-12-26 15:33:18
【问题描述】:
我有下面的方法 http 在角度 2 与 {"Content-Type": "application/json",'Authorization':this.authToken} 设置标题
public allJobsStageWidget1= (): Observable<WidgetModel[]> => {
let widget1Url= this._configuration.ServerWithApiUrl + 'getAllJobsStagesCount';
return this._http.get(widget1Url,new RequestOptions({
headers: new Headers({"Content-Type": "application/json",'Authorization':this.authToken})
}))
.map((response: Response) => {console.log(response.json());response.json() })
.catch(this.handleError);
}
在我的节点应用程序中,完成了以下事情:
app.use(function(req, res, next) {
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type,Authorization ,Accept');
next();
});
当我发出GET 请求时,会抛出'XMLHttpRequest cannot load http://rest-0023:3000/api/getAllJobsStagesCount. Response for preflight has invalid HTTP status code 403' 错误,因为我已经设置了所有标头。但我不知道我在哪里遗漏了一些东西。
【问题讨论】:
-
我遇到了同样的问题。你得到解决方案了吗?
标签: node.js angular http-headers content-type angular2-http