5

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.

Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66
Zsolt Gonye
  • 51
  • 1
  • 3
  • RequestCredentialsOpts.Include has been removed, but for the moment, it's not any information about the right way in the future to set withCredentials -> https://github.com/angular/angular/issues/4231 – Dani Nov 28 '15 at 10:29
  • Answering my question. One of the principal Angular2 developers has fixed the issue, we'll be able to work with 'withCredentials' again. -> https://github.com/angular/angular/pull/5501 – Dani Nov 28 '15 at 11:12

1 Answers1

6

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;
    ........

:)

marveloper
  • 61
  • 3