【发布时间】:2018-06-16 13:34:22
【问题描述】:
我有以下代码在没有身份验证的情况下进行 get http 调用,一切正常。
让 headers2 = {'Content-Type': 'application/json'}; his.http.get('https://api.test.com/account/get/',headers2).map(res => res.json()).subscribe(data => { this.posts = 数据;});
但我不知道如何添加上述基本身份验证,就像这样(在 curl 中)但在 ionic 中:
curl --user admin:password -s -X GET "https://api.test.com/account/get/" -H "content-type: application/json"
无论我尝试什么,都会出现 401 身份验证错误。
谢谢
【问题讨论】:
-
它不适用于角度......我试过这个 this.http.get('admin:password@api.test.com/account/get/',headers2).map(res = > res.json()).subscribe(data => { this.posts = data;
-
不一样,我用的是基本认证,不是token。
-
如果您阅读该问题,您会看到答案的最后一部分是关于令牌的......
标签: angular api ionic-framework https