Zsolt Gonye
Zsolt Gonye

Reputation: 51

Angular 2 Http request does not send credentials

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.

Upvotes: 5

Views: 3900

Answers (1)

marveloper
marveloper

Reputation: 61

I'm using [email protected];

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

this._xhr.withCredentials = true;

[email protected]/src/http/backends/xhr_backed.js

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

:)

Upvotes: 6

Related Questions