javascript - How to intercept ajax requests sent by `axios` in nodejs?
巴扎黑
巴扎黑 2017-07-05 10:36:01
0
3
868

After a general front-end library sends an ajax request, the response object headers will have X-Requested-With:XMLHttpRequest
but## The ajax request sent by #axios does not have this field in the response header

How to intercept the front-end request sent by

axios in nodejs code?

巴扎黑
巴扎黑

reply all(3)
扔个三星炸死你

I want to add X-Requested-With header to every request:

axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

To intercept the sent ajax, just use spy to replace XMLHttpRequest with the original method.

I can’t figure out why axios doesn’t add this header by default. . .

巴扎黑

Add proxy plug-in to intercept it

Peter_Zhu

Are you sure it's an axios problem? Have you tried using another tool? Ajax and axios are just tools for transmitting http requests, so I want to point out that the ajax request sent by the poster's axios is wrong. In addition, I don't know your backend. How to write it? If no acceptable request header is configured when crossing domains, the specified header data will not be obtained. "Access-Control-Allow-Headers": "X-Requested-With"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template