我正在使用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。
答案 0 :(得分:6)
我正在使用angular2@2.0.0-alpha.37
;
如果您在xhr_backed.js
中添加代码,则可以发送'凭据'到服务器
this._xhr.withCredentials = true;
var XHRConnection = (function() {
function XHRConnection(req, browserXHR, baseResponseOptions) {
........
this._xhr = browserXHR.build();
this._xhr.withCredentials = true;
........
:)