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
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
How many ways can you get a web page?
 
How many ways can you get a web page?
  
This works in Bourne and Bash -- note that Bash `echo` behaves the opposite of Bourne!
+
This works in Bourne and Bash. The "if" statement is to get around differences between the shell built-ins versus the stand-along in '''/bin/echo'''.
 
<pre>
 
<pre>
 
if echo -e | grep -q -- -e; then
 
if echo -e | grep -q -- -e; then
Line 19: Line 19:
 
</pre>
 
</pre>
  
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.
+
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>
 +
 
 +
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 remote server closes the connection, so no `sleep` is necessary.
 
<pre>
 
<pre>
 
(echo 'GET /dotfiles HTTP/1.1';echo 'Host: www.noah.org';echo;echo) | nc www.noah.org 80
 
(echo 'GET /dotfiles HTTP/1.1';echo 'Host: www.noah.org';echo;echo) | nc www.noah.org 80
 
</pre>
 
</pre>

Latest revision as of 06:55, 23 September 2010


How many ways can you get a web page?

This works in Bourne and Bash. The "if" statement is to get around differences between the shell built-ins versus the stand-along in /bin/echo.

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 remote 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