0

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.

4ndt3s
  • 3,238
  • 2
  • 20
  • 30
Rob DePietro
  • 284
  • 2
  • 8
  • 23

1 Answers1

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
  • @cnishina is it better like that? – Abel Valdez Apr 11 '18 at 00:04
  • Looks better. The initial question is vague. – cnishina Apr 13 '18 at 17:18