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

问题描述

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

解决方法

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。