angular2 xhrfields withcredentials真 [英] angular2 xhrfields withcredentials true
本文介绍了angular2 xhrfields withcredentials真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图登录到系统中。在1角,有方法来设置
withCredentials:真
但我无法找到angular2工作sollution
出口类LoginComponent {
构造函数(公共_router:路由器,公共HTTP:HTTP,){ }
的onsubmit(事件,用户名,密码){
this.creds = {'邮箱':'harikrishna@gmail.com','密码':'01010','与rememberMe':真正}
this.headers =新的报头();
this.headers.append('内容类型,应用/ JSON'); this.http.post(的http:// XYZ / API /用户/登录,{},this.creds)
.subscribe(RES => {
的console.log(res.json()的结果。); });
}}
解决方案
据我所知,现在(beta.1)的选项不可用。
您必须解决它是这样的:
让_build = http._backend._browserXHR.build;http._backend._browserXHR.build =()=> {
让_xhr = _build();
_xhr.withCredentials = TRUE;
返回_xhr;
};
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);
});
}
}
解决方案
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;
};
这篇关于angular2 xhrfields withcredentials真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文