简体   繁体   English

如何在XmlHttpRequest中使用Angular拦截器

[英]How to use Angular interceptor in XmlHttpRequest

I am using Angular 4. Also used the http interceptor for any http request. 我正在使用Angular4。还对任何HTTP请求都使用了HTTP拦截器。 https://angular.io/api/common/http/HttpInterceptor https://angular.io/api/common/http/HttpInterceptor

But I am using one of the post request using xmlHttpRequest for some file upload event. 但是我正在使用xmlHttpRequest的发布请求之一来进行一些文件上传事件。 headers are setting properly in http post request (this.http.post(...)). 标头已在http发布请求(this.http.post(...))中正确设置。 But In xmlHttpRequest, interceptor is not being called. 但是在xmlHttpRequest中,没有调用拦截器。 so cannot set the header. 因此无法设置标题。 How can i handle the http interceptor in xmlHttpRequest(post method)? 我该如何处理xmlHttpRequest(post方法)中的HTTP拦截器?

Interceptor will work just for request which is made by HttpClient , why that is not working. 拦截器仅对HttpClient发出的请求起作用,为什么不起作用。 Even you can try to make request with old Http module from angular instead of HttpClient , also it won't work. 即使您可以尝试使用旧的Http模块从angular而不是HttpClient发出请求,也无法正常工作。

Interceptor transform any request GET/POST/PUT..might be something is missing in code. 拦截器转换任何请求GET / POST / PUT ..可能是代码中缺少的内容。 Can you please share your code so that i can check issue. 能否请您分享您的代码,以便我检查问题。 Also you can refer this blog ..given very simple way of Interceptor implementation with example. 您也可以参考此博客 ..给出非常简单的Interceptor实现方式的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM