Angular2和Node:Preflight的响应具有无效的HTTP状态码403

我有以下方法为angular2中的标头与{"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' 'XMLHttpRequest cannot load http://rest-0023:3000/api/getAllJobsStagesCount. Response for preflight has invalid HTTP status code 403'错误,因为我已经设置了所有标题。 但我不知道我在哪里丢失东西。

看来你还没有拒绝授权方法。 我认为标题行应该是这样的:

 headers: new Headers({ "Content-Type": "application/json", "Authorization": "Basic " + this.authToken })