我正在尝试使用 withCredentials 将 cookie 发送到我的服务,但不知道如何实现它。文档说“如果服务器需要用户凭据,我们将在请求标头中启用它们”,没有示例。我尝试了几种不同的方法,但它仍然不会发送我的 cookie。到目前为止,这是我的代码。
private systemConnect(token) {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('X-CSRF-Token', token.token);
let options = new RequestOptions({ headers: headers });
this.http.post(this.connectUrl, { withCredentials: true }, options).map(res => res.json())
.subscribe(uid => {
console.log(uid);
});
}