Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 985
Zsolt Gonye Avatar asked Oct 02 '15 10:10

Zsolt Gonye


1 Answers

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

:)

like image 104
marveloper Avatar answered Sep 18 '22 13:09

marveloper