有什么想法吗?我仍然遇到同样的问题.有人可以建议我如何正确更新标头.解决方案我认为问题在于克隆请求.您需要执行以下操作.request = request.clone({ headers: request.headers.set("Authorization", `sample-auth`)});I am working with Http interceptor and trying to retry the failed request to handle 401 error. I am trying to set a new header to update the request but it's not working.I noticed that My header is not being set with the request instead it's going to the lazyUpdates inside headers. Can anyone provide me the any idea why it's happening. After checking my networks I found that with the retry request old header is passed which is 'x-auth-token' and new headers are not sent.interceptor.tsintercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { request = request.clone({ setHeaders: { 'x-auth-token': this.authService.getToken() } }); return next.handle(request).do(event => {}, err => { if (err instanceof HttpErrorResponse && err.status == 401) { request = request.clone({ setHeaders: { 'Content-Type': 'application/json', 'Authorization': 'sample-auth' } }); return next.handle(request) } }); }Header that contains values in lazy loading instead of headers:I have already gone through this linkAny ideas?I am still having same issue. would anyone please suggest me what can be done to update headers properly. 解决方案 I think the problem is with cloning of the request. You need to do something like this.request = request.clone({ headers: request.headers.set("Authorization", `sample-auth`)}); 这篇关于无法从拦截器角度2/4成功更新请求标头(401处理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 13:16