Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an API, which I need to consume to create reports, However that API requires username and password to access it, by using curl command I can access the API

curl -X GET "https://SomeApiCall/api/v1/customers/" -H "accept:application/json; charset=UTF-8" -u "username:password"

but when I am trying to use same API using angular I am getting below error

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 sample code:

 this.data = this.http.get("https://SomeApiCall/api/v1/customers/" , {
      headers: new HttpHeaders({
        'Authorization': 'Basic' + btoa('username:password'),
        'Content-Type':  'application/json'
      })
    });

Can someone explain, what mistake I am making ?

question from:https://stackoverflow.com/questions/65881193/cant-access-api-using-angular

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

I think the problem is that you don't have a space after 'Basic'. Change to:

 this.data = this.http.get("https://SomeApiCall/api/v1/customers/" , {
  headers: new HttpHeaders({
    'Authorization': 'Basic ' + btoa('username:password'),
    'Content-Type':  'application/json'
  })
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...