How can I add a header for username and password for GET Request in http in angular2?
I am try to add httpclient and http import is not working. Can you suggest to me how to add a header in http and pass my username and password?
How can I add a header for username and password for GET Request in http in angular2?
I am try to add httpclient and http import is not working. Can you suggest to me how to add a header in http and pass my username and password?
You can set the header like this:
yourMethodWhereYouPost(userName:string, password:string)
{
// ....
// Your code
//
// Get the authorization header.
const authHeader = this.getAuthorizationHeader(userName, password);
const headers = new Headers({ 'Content-Type': 'application/json' });
headers.append('Authorization', authHeader);
// ....
// Some more code
}
private getAuthorizationHeader(userName: string, password: string): string
{
// Return the encoded auth header.
return btoa(userName + ':' + password);
}