view raw
Avinash Bhawnani Avinash Bhawnani - 7 months ago 57
HTTP Question

Asking a HTTP GET request with netcat

So, I have to retrieve temperature from any one of the cities from

Let's assume I want to retrieve of Kanpur's.

How to make an HTTP GET request with Netcat?

I'm doing something like this.

nc -v 80

I don't know exactly if I'm even in the right direction or not. I am not able to find any good tutorials on how to make an HTTP get request with netcat, so I'm posting it on here.


Of course you could dig in standards searched for google, but actually if you want to get only a single URL, it doesn't worth the effort.

You could also start a netcat in listening mode on a port:

nc -l 64738

...and then do a browser request into this port with a real browser. Just type in your browser http://localhost:64738 and see.

In your actual case the problem is that HTTP/1.1 doesn't close the connection automatically, but it waits your next URL you want to retrieve. The solution is simple:

Use HTTP/1.0:

GET /this/url/you/want/to/get HTTP/1.0
<empty line>

or use a Connection: request header to say the server you want to close after that:

GET /this/url/you/want/to/get HTTP/1.1
Connection: close
<empty line>

Extension: After the GET header write only the path part of the request. The hostname from which you want to get data belongs to a Host: header as you can see in my examples. This is because multiple websites can run on the same webserver, so the browsers need to say him, from which server they want to load the page.