我有这个拦截器,我需要添加一个后端期望的完全自定义标头。但是,如果启用,则请求将永远不会到达API。后端以django编写,这意味着自定义标头以HTTP_HEADERNAME格式命名。我认为这是我的拦截器,但是我似乎找不到它,因为令牌确实随每个请求以及内容类型附加:
export class InterceptAPICalls implements
HttpInterceptor {
constructor() {}
intercept(
req: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
try {
const token = currentUserToken();
// add it if we have one
if (token) {
req = req.clone({
headers: req.headers.set("Authorization", "Bearer " + token)
});
}
} catch (e) {
if (e instanceof TypeError) {
}
}
// setting the accept header
req = req.clone({
headers: req.headers.set("Accept", "application/json")
});
//add custom header QNA
req = req.clone({ headers: r eq.headers.set("HTTP_QNA", 'z9') });
return next.handle(req);
}
}
如何将标头QNA作为请求的一部分传递?