2016-08-19 54 views
2

我已经设置与{"Content-Type": "application/json",'Authorization':this.authToken}Angular2和节点:对于预检响应具有无效的HTTP状态代码403

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); 
    } 

,在我的节点应用http在角2与头部以下的方法,下面的事情完成:

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'引发错误,因为我已经设置的所有头。但我不知道我在哪里丢失东西。

+0

我有同样的问题。你有解决方案吗? – Amir

回答

0

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

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