10
2
With the command telnet docs.python.org 80
, I can do a manual HTTP request to http://docs.python.org/2/license.html
, by typing the actual request.
Now, instead of typing it in live, I'd like to feed the request from a text file.
I tried this:
cat request.txt|telnet docs.python.org 80
request.txt:
GET /2/license.html HTTP/1.1
Host: docs.python.org
(You have to finish the file with a blank line or you'll get a bad request!)
But the connection to the server is closed immediately.
How should I properly pipe request.txt to telnet docs.python.org 80
?
edit:
It's good to know; if you use HEAD
instead of GET
, you will get the same response as if you did a GET
request, except for the message body.
So, use HEAD
if you just want to examine the HTTP headers. (i.e. So that the contents of the response doesn't clutter your shell output.)
@Bentley4 You actually type
<ENTER>
? – voices – 2016-05-31T08:59:34.337Could you include the actual command you run manually so we can compare? When I run the
GET
you have posted, I get a408 Request Time-out
error. Also, iswget http://docs.python.org/2/license.html
not an option? – terdon – 2013-11-07T14:21:06.307The commands are correct. I think you are making a connection with the server the moment you enter
telnet docs.python.org 80
, so you 'll have to hurry and type in those two lines(copy paste if necc.) within a few seconds or the server will return a time-out error. – Bentley4 – 2013-11-07T17:09:22.773These are the exact commands:
telnet docs.python.org 80
<ENTER>
GET /2/license.html HTTP/1.1
<ENTER>
Host: docs.python.org
<ENTER>
<ENTER>
– Bentley4 – 2013-11-07T17:10:31.8731
I think the reason why you need to type
– Bentley4 – 2013-11-07T17:14:52.880<ENTER>
a second time at the end is because the HTTP protocol requires an extra empty line after the request headers. See the request message section of the HTTP wiki article@ the
wget
solution: I want to define my request manually, with headers and all. That line in wget you proposed defines headers and message body automatically. – Bentley4 – 2013-11-07T17:19:30.7331Dammit, theoretically, you should be able to do
telnet < request.txt
but I can't get theGET
command to work. – terdon – 2013-11-07T17:24:44.753