角2 HTTP请求不发送凭据 [英] Angular 2 Http request does not send credentials

查看:316
本文介绍了角2 HTTP请求不发送凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与角2个工作,我尝试发送带有凭据的HTTP请求:

I am working with Angular 2 and I am trying to send HTTP request with credentials:

此角1 code效果很好,它包括凭据:

This Angular 1 code works well, it includes the credentials:

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

根据API preVIEW我已经实现这个角2 code,但它不包括凭据:

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

我与角2.0.0 alpha.37工作。

I am working with Angular 2.0.0-alpha.37.

推荐答案

我用 angular2@2.0.0-alpha.37 ;

如果您在 xhr_backed.js 添加code,您可以发送凭证到服务器

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

:)

这篇关于角2 HTTP请求不发送凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆