withCredentials不属于请求标头

时间:2017-04-19 14:30:07

标签: angular http xmlhttprequest

在带有和不带有withCredentials xhrField的chrome控制台中使用xhr请求会显示相同的请求标头属性。

如何将withCredentials映射到请求标头?

打字稿调用(Angular 2):

login(username : string, password : string) {
    let data = {username: username, password: password}
    return this.http.post(environment.apiEndpoint + 'login', data, { withCredentials: true })
      .catch((error) => {
        return Observable.throw(error.json());
      });
  }

注意:这是一个跨域通话,即使服务器发送了cookie,我也不会收到cookie(set-cookie标题字段)

1 个答案:

答案 0 :(得分:0)

根据MDN

  

XMLHttpRequest.withCredentials属性是一个布尔值,指示是否应使用Cookie,授权标头或TLS客户端证书等凭据进行跨站点访问控制请求。设置withCredentials对同站点请求没有影响。

这意味着在跨站点请求时,它会在同源请求中添加cookie,tls证书和Authorization标头:没有。它还允许X-site XHR设置cookie,而这通常不是这种情况。

相关问题