如何删除角度 6 中发布请求的请求标头中的 cookie 参数

问题描述 投票:0回答:1

发送 post 请求时,cookie 参数在请求标头中设置。 有什么方法可以停止在 api 请求标头中发送 cookie 参数 对于角度拦截器中的特定 api 调用

angular6 angular-http-interceptors request-headers
1个回答
0
投票

http module
默认情况下不设置 cookie 参数。当您收到响应时,http 模块会丢弃该 cookie,并且不会将其添加到后续请求中。所以你手动添加了它:

checkAuth() {
    // if we did not add { withCredentials: true }, response would be false because, 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}
添加到每个请求中。相反,我们编写拦截器,修改请求对象并默认添加cookie。

© www.soinside.com 2019 - 2024. All rights reserved.