这是我的代码
gettheLinkedinUserDetails(token: string) {
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append('Authorization','Bearer '+token);
this.http.get('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url)?format=json',{headers: headers})
.subscribe(profileData => {
alert(profileData + 'hii');
})
}我使用的是HttpClientModule &我得到的错误是
Argument of type '{ headers: Headers; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'. Types of property 'headers' are incompatible. Type 'Headers' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'. Type 'Headers' is not assignable to type '{ [header: string]: string | string[]; }'. Index signature is missing in type 'Headers'.如何解决此问题?
发布于 2018-08-31 01:27:50
使用HttpHeaders而不是@angular/common/http中的Headers。
gettheLinkedinUserDetails(token: string) {
let headers: new HttpHeaders(
{ 'Content-Type': 'application/x-www-form-urlencoded' },
{ 'Authorization','Bearer ' + token });
this.http.get('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url)?format=json',
{headers: headers})
.subscribe(profileData => {
alert(profileData + 'hii');
});
}https://stackoverflow.com/questions/52102285
复制相似问题