【发布时间】:2020-09-29 12:05:56
【问题描述】:
当发送一个 post 请求时,cookie 参数被设置在请求标头中。 有没有办法停止在 api 请求标头中发送 cookie 参数 用于角度拦截器中的特定 api 调用
【问题讨论】:
标签: angular6 angular-http-interceptors request-headers
当发送一个 post 请求时,cookie 参数被设置在请求标头中。 有没有办法停止在 api 请求标头中发送 cookie 参数 用于角度拦截器中的特定 api 调用
【问题讨论】:
标签: angular6 angular-http-interceptors request-headers
http module 默认不设置 cookie 参数。当您收到响应时,http 模块会丢弃该 cookie,并且不会将其添加到后续请求中。所以你已经手动添加了:
checkAuth() {
// if we did not add { withCredentials: true }, response would be false becasue, cookies wont be attached
return this.http.get<SignedinResponse>(this.rootUrl + '/signedin',{withCredentials:true}).pipe(
tap(({ authenticated }) => {
// console.log('response from /signedin', res);
})
);
}
您必须手动将{withCredentials:true} 添加到每个请求中。取而代之的是我们编写拦截器,来修改req obj并默认添加cookie。
【讨论】: