【问题标题】:Angular 2 Http request does not send credentialsAngular 2 Http 请求不发送凭据
【发布时间】:2015-12-30 13:25:43
【问题描述】:

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

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

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

根据 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)
    );

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

【问题讨论】:

标签: angular http typescript credentials


【解决方案1】:

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

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

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

:)

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-09-15
  • 2021-12-29
  • 1970-01-01
  • 2017-05-12
  • 2018-08-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多