Authorization Basic headers not working in ionic 2


#1

How I set my headers. Find almost website but no any solution. How did you solve that problem? I have User name or password and set header properly but did not work set header. Also response 401 error because header Authorization not set.

let username: string = ‘username’;
let password: string = ‘password’;
let headers: Headers = new Headers();
headers.append(“Accept”, ‘application/json’);
headers.append(“Authorization”, "Basic " + btoa(username + “:” + password));
headers.append(‘Content-Type’, ‘application/x-www-form-urlencoded’);
let options = new RequestOptions({ headers: headers });

var url = “http://MYURL?grant_type=password&username=“name”&password=“pwd”
this.http.post(url, options)
.subscribe(res => {

console.log(res[’_body’]);

}, (err) => {
console.log(“Somthing went wrong!”+err);
});

Please resolve my issue how to get proper response. ThankYou