angular 7中的HTTP拦截器未添加标头

时间:2019-04-22 19:19:59

标签: angular angular7

我正在尝试使用以下代码在http标头中设置auth令牌。它不会在标头中设置身份验证令牌。我在这里想念什么?尝试了下面链接中提供的解决方案,但是没有运气。

https://stackoverflow.com/questions/54820257/angular-7-httpinterceptor-not-adding-header-to-request
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
        const token: string = sessionStorage.getItem('token');
        request = request.clone({ url: `${this.baseUrl}/${request.url}` });

        const clonedRequest = request.clone({
            headers: new HttpHeaders({
                Authorization: token,
                "Content-Type": "application/json"
            })
        });
        return next.handle(clonedRequest);
    }

1 个答案:

答案 0 :(得分:0)

不是由于授权周围缺少“”引起的吗?