首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型为'{ headers: Headers;}‘的参数不能赋值给参数: Ionic

类型为'{ headers: Headers;}‘的参数不能赋值给参数: Ionic
EN

Stack Overflow用户
提问于 2018-08-31 01:09:16
回答 1查看 1.7K关注 0票数 1

这是我的代码

代码语言:javascript
复制
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'.如何解决此问题?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-31 01:27:50

使用HttpHeaders而不是@angular/common/http中的Headers

代码语言:javascript
复制
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');
          });
      }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52102285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档