【发布时间】:2022-01-25 13:44:17
【问题描述】:
问题
我正在尝试设置一个名为 Cookie 的标头。我使用拦截器执行此操作,以便在每次请求时完成。
代码
@Injectable
export class HeaderInterceptor implements HttpInterceptor {
constructor(private: authService: AuthenticationService) {}
intercept(reg: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return from(this.authService.getAuthentication()).pipe(
switchMap((token) => {
const headers = req.headers
.set(TOKEN, "someToken")
.set("Cookie", "someCookie")
.append("Content-Type", "application/json")
.append("Accept", "application/json");
const requestClone = req.clone({ headers, withCredentials: true });
return next.handle(requestClone);
})
);
}
}
会发生什么
我总是得到:
尝试设置禁止的标头被拒绝:Cookie
那么我可以在这里做什么?我还尝试在每个请求上直接设置withCredentials: true,但这也不起作用。有没有其他办法?
【问题讨论】:
标签: javascript angular http cors http-headers