Difference between revisions of "HTTP GET"

From Noah.org
Jump to navigationJump to search
m (Created page with 'Category: Engineering How many ways can you get a web page? This works in Bourne and Bash -- note that Bash `echo` behaves the opposite of Bourne! <pre> if echo -e | grep -…')
 
m
Line 17: Line 17:
 
<pre>
 
<pre>
 
(echo 'GET /dotfiles HTTP/1.1';echo 'Host: www.noah.org';echo;echo; sleep 2 ) | telnet www.noah.org 80
 
(echo 'GET /dotfiles HTTP/1.1';echo 'Host: www.noah.org';echo;echo; sleep 2 ) | telnet www.noah.org 80
 +
</pre>
 +
 +
This one gets rid of the HTTP response header by deleting everything up to and including the first blank line.
 +
<pre>
 +
(echo 'GET /dotfiles HTTP/1.0';echo 'Host: www.noah.org';echo;echo;sleep 1) | telnet www.noah.org 80 2>/dev/null | sed '1,/^$/ d'
 
</pre>
 
</pre>
  

Revision as of 05:03, 23 February 2010


How many ways can you get a web page?

This works in Bourne and Bash -- note that Bash `echo` behaves the opposite of Bourne!

if echo -e | grep -q -- -e; then
    echo "sh style"
    (echo 'GET /dotfiles HTTP/1.1\nHost: www.noah.org\n\n'; sleep 2 ) | telnet www.noah.org 80
else
    echo "Bash style"
    (echo -e 'GET /dotfiles HTTP/1.1\nHost: www.noah.org\n\n'; sleep 2 ) | telnet www.noah.org 80
fi

It's probably just as well to use multiple `echo` statements since this will work on both:

(echo 'GET /dotfiles HTTP/1.1';echo 'Host: www.noah.org';echo;echo; sleep 2 ) | telnet www.noah.org 80

This one gets rid of the HTTP response header by deleting everything up to and including the first blank line.

(echo 'GET /dotfiles HTTP/1.0';echo 'Host: www.noah.org';echo;echo;sleep 1) | telnet www.noah.org 80 2>/dev/null | sed '1,/^$/ d'

You can do a similar thing with netcat (`nc`). Notice that the `telnet` version requires a `sleep` to give time for the data to come back whereas the `nc` version waits until the remove server closes the connection, so no `sleep` is necessary.

(echo 'GET /dotfiles HTTP/1.1';echo 'Host: www.noah.org';echo;echo) | nc www.noah.org 80