如何解决无法使用 angular 访问 api
我有一个 API,我需要使用它来创建报告,但是该 API 需要用户名和密码才能访问它,通过使用 curl 命令我可以访问该 API
curl -X GET "https://SomeApiCall/api/v1/customers/" -H "accept:application/json; charset=UTF-8" -u "username:password"
但是当我尝试使用 angular 使用相同的 API 时,出现以下错误
key:"api.error.invalid_auth_schema"
message: "Invalid authentication scheme is used. Only Basic Authentication scheme is supported (login and password should be provided)"
Angular 示例代码:
this.data = this.http.get("https://SomeApiCall/api/v1/customers/",{
headers: new HttpHeaders({
'Authorization': 'Basic' + btoa('username:password'),'Content-Type': 'application/json'
})
});
谁能解释一下,我犯了什么错误?
解决方法
我认为问题在于您在“基本”之后没有空格。更改为:
this.data = this.http.get("https://SomeApiCall/api/v1/customers/",{
headers: new HttpHeaders({
'Authorization': 'Basic ' + btoa('username:password'),'Content-Type': 'application/json'
})
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。