harikrish harikrish - 3 months ago 66
HTTP Question

angular2 xhrfields withcredentials true

I am trying to login to a system. In angular 1, there was ways to set

withCredentials:true


But i could not find a working sollution in angular2

export class LoginComponent {
constructor(public _router: Router, public http: Http, ) {

}


onSubmit(event,username,password) {
this.creds = {'Email': 'harikrishna@gmail.com','Password': '01010','RememberMe': true}
this.headers = new Headers();
this.headers.append('Content-Type', 'application/json');

this.http.post('http://xyz/api/Users/Login', {}, this.creds)
.subscribe(res => {
console.log(res.json().results);

});
}

}

Answer

AFAIK, right now (beta.1) the option is not available.

You have to work around it with something like this:

let _build = http._backend._browserXHR.build;

http._backend._browserXHR.build = () => {
  let _xhr =  _build();
  _xhr.withCredentials = true;
  return _xhr;
};
Comments