Sunday, February 5, 2017

Linux utility to execute HTTP requests and examine raw responses



I'm learning about the HTTP protocol and I'd like to know if there's a tool I can use to input a HTTP request I have created myself that will output the raw response. I've had a look at cURL and wget but they don't seem to have an obvious option to do this. For example:



$ http_response < my_http_request.txt
HTTP/1.0 200 OK

Date: Sat, 24 Jul 2010 18:43:58 GMT
etc..

Answer



Many people will recommend telnet for this, and it works, but I prefer to use netcat. The reason is that telnet was designed to work with a particular protocol, the TELNET protocol (which I'm not even sure anyone uses anymore...), so it's got all sorts of bells and whistles (i.e. it recognizes a whole bunch of options and commands and escape characters) that are completely irrelevant for HTTP. On the other hand, netcat simply takes its standard input and sends it out, byte-for-byte, over the network. Nothing more. That's exactly what you need to send a raw HTTP request.



There are various versions of netcat but generally their usage is the same as telnet:



netcat host port < my_http_request.txt



(on my computer the program name is nc6 rather than netcat, so substitute as appropriate)


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...