Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make an HTTP GET request manually with netcat?

Tags:

http

get

netcat

So, I have to retrieve temperature from any one of the cities from http://www.rssweather.com/dir/Asia/India.

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 rssweather.com 80 GET http://www.rssweather.com/wx/in/kanpur/wx.php HTTP/1.1 

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.

like image 943
Avinash Bhawnani Avatar asked Sep 01 '15 21:09

Avinash Bhawnani


People also ask

How do I send a HTTP request in nc?

Just type in your browser http://localhost:64738 and see. 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.

Does netcat use HTTP?

Majority of the traffic over the internet is HTTP Traffic. There is a HTTP Client which wants some data from HTTP Server, so it creates a HTTP Request Message in the protocol understandable by the server and sends it.


1 Answers

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

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

nc -l 64738 

(Sometimes nc -l -p 64738 is the correct argument list)

...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 Host: www.rssweather.com <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 Host: www.rssweather.com 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 site it wants to load the page.

like image 58
peterh Avatar answered Oct 07 '22 03:10

peterh