Use case: Usually, when integrating with external service endpoints in your backend application, you will be using libraries (require('https')
for Nodejs, import requests
or import aiohttp
for Python, HttpUrlConnection
for Java, etc.)
to make HTTP calls. It might be difficult to debug what request headers and payload are sent to remote instances; in this case, tcpdump
can show how the request is structured (headers and payload) and forwarded to the server; this will help debug.
Make sure you have tcpdump
installed. In general, if the service you are integrating is on http
, you can use a command
like below to see how the request is sent.
First, using ifconfig
find the network interface used to communicate with the internet.
And you can use tcpdump
to see the network traffic sent to an external service.
Note: here utun2
is the network interface and integrated.service.com is the service endpoint host to which the request is sent.
You should see request headers and payload, but for the HTTPS
endpoint, you would see encrypted data.
In this case, you can start a simple web server using - python3 -m http.server 4000
(you can use any port here.)
All localhost/127.0.0.1 traffic goes to another interface, mostly lo
for Linux and lo0
for macOS (you can check using
ifconfig
). You can use tcpdump
like below and use port
instead of host.
Now in your application, instead of the actual service endpoint, you can put http://localhost:4000
and make the
call; you should be seeing something like below -
You can see how request
headers and (after a few lines) the payload {"notification": {"data": {" ...
are sent.
Thus using tcpdump
and creating a fake HTTP server, you can peek at the request payload sent to the remote server. I hope this helps.
– RC
Comments