Angular 2 Http request does not send credentials

浪子不回头ぞ 提交于 2019-12-01 03:26:10

问题


I am working with Angular 2 and I am trying to send HTTP request with credentials:

This Angular 1 code works well, it includes the credentials:

$http.get("http://some.com/user",{ withCredentials: true})

According to the API preview I have implemented this Angular 2 code but it does not include credentials:

    http.get("http://some.com/user", {
        headers: myHeaders,
        credentials: RequestCredentialsOpts.Include
    }).toRx()
        .map(res => res.json())
        .subscribe(
        // onNext callback
            data => this.successHandler(data),
        // onError callback
            err  => this.failure(err)
    );

I am working with Angular 2.0.0-alpha.37.


回答1:


I'm using angular2@2.0.0-alpha.37;

If you add code in xhr_backed.js, You can send 'credentials' to server

this._xhr.withCredentials = true;

angular2@2.0.0-alpha.37/src/http/backends/xhr_backed.js

var XHRConnection = (function() {
  function XHRConnection(req, browserXHR, baseResponseOptions) {
    ........
    this._xhr = browserXHR.build();
    this._xhr.withCredentials = true;
    ........

:)



来源:https://stackoverflow.com/questions/32905399/angular-2-http-request-does-not-send-credentials

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!