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
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"
I want to add
X-Requested-With
header to every request: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
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"