pun*_*ter 1 http-headers angular angular-httpclient
这在Angular 4中有效。要使其在Angle 5中正常工作,我需要进行哪些更改?
getGreeting(): Observable<string> {
let headers = new Headers({ 'Authorization': 'Bearer ' + this.authenticationService.token });
//cant find requestoptions
let options = new RequestOptions({ headers: headers });
return this.http.
get(Constant.ApiRoot + Constant.GreetingService, options).
map((response: Response) => response.text());
}
Run Code Online (Sandbox Code Playgroud)
小智 5
标头可以作为HttpHeaders或Plain JSON对象传递,但它应该是HttpOptions的一部分。您可以在Angular的官方文档中找到有关它的更多信息,网址为https://angular.io/guide/http#adding-headers
const httpOptions = {
headers: new HttpHeaders({
'Authorization': Bearer ' + this.authenticationService.token
})
};
this.httpClientObj.get('url',httpOptions);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6309 次 |
| 最近记录: |