angular2 xhrfields withcredentials true

har*_*ish 5 javascript http angular

我正在尝试登录系统.在角度1中,有设置的方法

withCredentials:true
Run Code Online (Sandbox Code Playgroud)

但我找不到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);

              });
     }

}
Run Code Online (Sandbox Code Playgroud)

max*_*lec 8

在Angular> 2.0.0(实际上来自RC2),只是

http.get('http://my.domain.com/request', { withCredentials: true })
Run Code Online (Sandbox Code Playgroud)


cex*_*yat 5

AFAIK,现在(beta.1)该选项不可用.

你必须用这样的东西解决它:

let _build = http._backend._browserXHR.build;

http._backend._browserXHR.build = () => {
  let _xhr =  _build();
  _xhr.withCredentials = true;
  return _xhr;
};
Run Code Online (Sandbox Code Playgroud)