【问题标题】:ionic 3 call api with header token带有标头令牌的 ionic 3 调用 api
【发布时间】:2019-04-04 19:46:27
【问题描述】:

我有 api url 和 token 。在邮递员中,api 工作正常并显示数据。我需要在控制台的 ionic 3 应用程序中显示数据有人知道我该如何显示吗?我试了一下,但它显示错误。

api:http://api.igiinsurance.com.pk:8888/insurance_takaful/insurance-api/get_panel_hospitals.php?offset=0&limit=100

令牌:ee66cf61762eab785b006186dbc8c980

邮递员截图:

我尝试使用此代码但无法正常工作。

  getDataUsingToken1(token) { 
    const httpOptions = {headers: new HttpHeaders().set("Authorization", "token "+token)}; 
     return this.httpClient.get('this.apiurl', httpOptions) 
  }; 

  ngOnInit() { 
    this.getDataUsingToken1(this.token).subscribe(data=>{ 
      console.log(data); 
    },
    err => console.log(err.message)
    );
  } 

【问题讨论】:

  • 'this.apiurl'?这真的是您的代码中的内容吗?向我们展示了整个班级。
  • 不,这里是 api 我只是在这里键入它来缩短代码

标签: angular ionic3 postman


【解决方案1】:

试试看:

getDataUsingToken1(token) { 
         return this.httpClient.get(this.apiurl,{headers:new HttpHeaders({
                  'token': token
                })) 
      }

【讨论】:

  • 给我截图
  • 你检查 CORS 政策了吗??
  • @UmaizKhan 哪里不见了,
  • })) 在这里我认为它说“,”在这里不见了
猜你喜欢
  • 2019-12-03
  • 2020-10-04
  • 2018-12-10
  • 1970-01-01
  • 2018-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-17
相关资源
最近更新 更多