Angular 2 Http请求不发送凭据

Zso*_*nye 5 http credentials typescript angular

我正在使用Angular 2,我正在尝试使用凭据发送HTTP请求:

这个Angular 1代码运行良好,它包含凭据:

$http.get("http://some.com/user",{ withCredentials: true})
Run Code Online (Sandbox Code Playgroud)

根据API预览,我已经实现了这个Angular 2代码,但它不包含凭据:

    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)
    );
Run Code Online (Sandbox Code Playgroud)

我正在使用Angular 2.0.0-alpha.37.

mar*_*per 6

我正在使用angular2@2.0.0-alpha.37;

如果您添加代码xhr_backed.js,您可以将"凭据"发送到服务器

this._xhr.withCredentials = true;
Run Code Online (Sandbox Code Playgroud)

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;
    ........
Run Code Online (Sandbox Code Playgroud)

:)

  • 它已由@robwormald修改 - > https://github.com/robwormald/angular/commit/547ea806b881969ded22d4c2880d403f0393bbab (2认同)