Angular 2 HTTP标头未添加到请求
问题描述:
我有以下http请求,在其中将标头添加到请求中,但是请求失败,并且当我在浏览器的网络"选项卡中查看时,请求标头不包含授权"标头.我在这里想念什么?
I have the following http request in which I add the header to the request, however the request fails and when I look in the Network tab of the browser the request headers don't include the Authorization header. What am I missing here?:
public get(address: string, callback: any): Observable<any> {
let headers: Headers = new Headers();
headers.append('Authorization', 'Bearer <token>');
return this.http.get(address, { 'Headers': headers })
.map(callback)
.catch((error: any) => this.handleError(error));
}
从网络"标签中请求标题:
Request Headers from the Network tab:
GET /v1/projects HTTP/1.1
Host: <host>
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Origin: http://localhost:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36
Accept: */*
Referer: http://localhost:8080/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8
答
Headers
应该是 headers
this.http.get(address, { headers: headers })