I need some assistance on examples of connecting an outside API to an Angular Application that has a username and password for authentication. I know how to connect an outside API that doesn't require authentication but I am trying to connect to an API that has a username and password as well as a proxy connection. And I am unsure how that is passed in the application? Any examples or help would be appreciated, thanks.
Asked
Active
Viewed 54 times
0
-
you need to provide more details on how the API accepts the username and password. Like query param, request headers etc., – Praveen Kumar Apr 10 '18 at 17:19
-
what is the API's request method GET or POST? – Deepinder Singh Apr 10 '18 at 17:37
-
Excuse my ignorance but I believe it will be through request headers. Also it is a GET request – Rob DePietro Apr 10 '18 at 17:48
-
To get better answers, you should probably include more information about this proxy and API, what you have tried, etc. – cnishina Apr 13 '18 at 17:20
1 Answers
0
The user and password are sending as headers then these headers you need put inside of Post method in the third parameter. This is an example.
let username: string = 'username';
let password: string = 'password';
let headers: Headers = new Headers();
headers.append("Authorization", "Basic " + btoa(username + ":" + password));
headers.append("Content-Type", "application/x-www-form-urlencoded");
this._http.post(url, data, {headers: headers})
Answer reference Http Auth

kangaroo_cliff
- 6,067
- 3
- 29
- 42

Abel Valdez
- 2,368
- 1
- 16
- 33
-
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/19394334) – cnishina Apr 10 '18 at 22:24
-
-