I am using Windows + Visual studio code to developer a Node JS API. I am using Axios to submit rest requests from NodeJs to third party API's.
I would like to inspect the packets sent from my Node server to the third party backend via Fiddler, however I have been having a hard time getting Axios to proxy through 127.0.0.1 port 8888.
Ideally it would be an easy global variable to set to turn on/off the proxy. the thing I have tried is:
axios.defaults.proxy = { host: "127.0.0.1", port:8888}
axios.defaults.proxy = { host: "127.0.0.1", port:8888, protocol: "http"}
axios.post(url: <api>, {post:data}, {proxy: {host: "127.0.0.1", "8888"} });
and a alot of different variations of the above. when the proxy is on, it won't complete the request.
Is the server you are trying to reach using https
? This is a problem with axios
that they seem to be having trouble solving.
A workaround that will allow you to proxy through Fiddler is to use an HTTPS-over-HTTP tunnel. Jan Molak wrote this nice article about the scenario of sending a request to an https
server through an http
proxy. The following code has worked for me when running requests through Fiddler:
const axios = require('axios');
const tunnel = require('tunnel');
const axiosInstance = axios.create({
httpsAgent = tunnel.httpsOverHttp({
host: '127.0.0.1',
port: 8888,
}),
proxy: false,
});
axiosInstance.post(/* ... */);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With