Recently I wanted to spy network traffic between a
a REST service. This task turned out to be more difficult than I
My first challenge was to force
HttpClient to use a proxy.
After a bit of googling I have found
the following code:
Unfortunately my REST service was exposed on
and later I found out that proxies are not used for local requests:
OK, no problem I though,
let’s just add another DNS alias to localhost -
just to fool
Uri class to think
that we are accessing some other machine.
This can be done by modifying
hosts file, which
on my Ubuntu machine is located in
Then I had to change my
And my REST service configuration so that it will listen for incoming connections on all interfaces:
After all these preparations I was able to intercept traffic using ZAP Proxy:
But was this all necessary? Turns out that not really.
You may use your vanilla
And then just set
http_proxy environmental variable to get
exactly the same behaviour (without any need to modify
to force REST service to listen on all interfaces).
Just run in Bash:
Since I don’t have any machine with Windows/MacOS I cannot confirm that it works on all OS’es, but at least it works on my Ubuntu.