Ionic 4中带有令牌的Http

问题描述 投票:0回答:1

((对不起我的英语不好),我必须访问一个api,并提供他们提供给我的令牌。我的问题是我不知道如何实现它,在搜索和搜索之后,它给了我以下错误:

已从起源'https://www.presupuestoabierto.gob.ar/api/v1/credito'到'http://localhost:8100'对XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:它没有HTTP正常状态。

我将代码传递给您,以表示在令牌(x而不是令牌)的定义中存在错误,并最终在CORS策略中,这是非常错误的,非常感谢!

const headers = { 'Authorization': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'http://localhost:8100'}
    this.http.get<any>('https://www.presupuestoabierto.gob.ar/api/v1/credito', { headers }).subscribe(data => {
      this.datos = data.blabla;
    })
ionic4
1个回答
0
投票

标题应该在Ionic-Angular中这样通过。确保您具有服务文件。访问此链接以了解有关服务的更多信息:

https://angular.io/tutorial/toh-pt4

let headers = new Headers({
'Content-Type' : 'application/json',
'Auth':authvalue
});

return this.http.get(url,options).pipe(map(res => res.json()));
© www.soinside.com 2019 - 2024. All rights reserved.