My application is sending HTTP requests to some server and I want to see the actual data that it is sending out. Some specifics I would like to see:
- Request method (GET/POST/PUT, etc.)
- Content-type
- Body
What is the best and simple way to accomplish this?
Well, for all those tcpdump fans =)
RUN ALL THESE COMMANDS AS ROOT !!!
Obtain root in a terminal with
To capture the RAW packets ...
This will capture all the raw packets, on all ports, on all interfaces and write them to a file,
/tmp/http.log
.Run your application. It obviously helps if you do not run any other applications that use HTTP (web browsers).
Kill
tcpdump
To read the log, use the
-A
flag and pipe the output toless
:The
-A
flag prints out the "payload" or ASCII text in the packets. This will send the output toless
, you can page up and down. To exitless
, type Q.When I go to Google, I see (in the raw packets):
tcpdump
has a long set of options to refine data collection from specifying network interfaces to ports to source and destination IP addresses. It can NOT decrypt (so it will not work with HTTPS).Once you know what you are interested in, you can use a number of options with
tcpdump
to record only the data of interest. The general strategy is to first record all the packets, review the raw data, and then capture only the packets of interest.Some helpful flags (options):
There is a learning curve, both to using
tcpdump
and learning how to analyze the data you collect. For further reading, I highly suggest Daniel Miessler'stcpdump
Primer with Examples.First install
tcpflow
from Ubuntu official repositories:Then run this command to inspect all HTTP requests on standard port:
I would suggest that you try Wireshark
Please note that Wireshark is quite advanced, and so may take a bit of getting used to. I have not used it for a few years, but it should still be perfect for what you are after - if not a bit too full of features.
Information about Wireshark and how to use it can be found at the Wireshark homepage.
Also possible with command, which gives tidy output, even for SSL: