我需要发送标题给我的HttpRequest。Angular 4.3 HttpClient - 如何正确使用HttpHeaders和拦截器?
我已经在这里搜索,我已经尝试了一些我找到的答案,但没有一个人工作。
标题不会被发送到API,如果我检查clonedRequest
对象,它不会显示标题。这是我的代码:
public intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Clone the request to add the new header.
const clonedRequest = req.clone();
clonedRequest.headers.set("ModuleId", this.dnnContext.moduleId);
clonedRequest.headers.set("TabId", this.dnnContext.tabId);
// Pass on the cloned request instead of the original request.
return next.handle(clonedRequest);
}
我缺少什么?
谢谢。现在我收到以下错误:TypeError:CreateListFromArrayLike在非对象上调用 – DAG
我想说,错误不会以任何方式与http客户端相关.... –
我在迁移之前没有发生此错误,无论如何我认为这与标题无关(我希望)...无论如何,感谢 – DAG