angular2 withCredentials = true在safari和IE

时间:2016-02-24 16:40:16

标签: xmlhttprequest angular

我正在尝试使用Web服务进行身份验证并进行后续的api调用。

export class HomeComponent {
  newName: string;

  headers = {
    headers: new Headers({
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    })
  };
  constructor(public http: Http, public nameListService: NameListService) {
    let _build = (<any>http)._backend._browserXHR.build;
    (<any>http)._backend._browserXHR.build = () => {
      let _xhr = _build();
      _xhr.withCredentials = true;
      return _xhr;
    };
  }
  login(path, data) {
    var creds = { 'Email': 'email@email.com', 'Password': 'pass', 'RememberMe': true };
    this.http.post('http://xx.net/api/Users/Login', JSON.stringify(creds), this.headers)
      .subscribe(res => {
      console.log(res);
      });
  }
  getdata() {
    this.http.get('http://xx.net/api/Users/LoggedInUser', this.headers)
      .subscribe(res => {
      console.log(res);
      }, (er) => {
        console.log(er);
      });
  }
}

在构造函数中我将_xhr.credentails设置为true。 Chrome中的一切都很棒,但IE和Safari都失败了。 当我尝试登录(在所有浏览器中)时,我可以看到带有“Set-Cookie”的响应标题,但是safari和IE似乎没有随后的请求发送此cookie,因此我得到401. Chrome正确地执行此操作。

这是框架的错误。

1 个答案:

答案 0 :(得分:1)

可能是Issue in this.withCredentials attribute in Cross Origin Resource Sharing

的副本

允许第三方Cookie的步骤:

  

IE 10 - 互联网选项&gt;隐私&gt;高级&gt;第三方Cookie&gt;接受

     

Safari - 偏好设置&gt;隐私&gt;阻止Cookie&gt;从未

相关问题