手で打って覚えるHTTP
ではさっそく,
$ telnet www.google.com 80 Trying 64.233.183.103... Connected to www.google.com (64.233.183.103). Escape character is '^]'. GET / HTTP/1.0 HTTP/1.0 302 Found Location: http://www.google.co.jp/ Cache-Control: private Content-Type: text/html; charset=UTF-8 Set-Cookie: PREF=ID=dcd5652deaacf010:FF=0:TM=1303887216:LM=1303887216:S=cUNIWkuapqmEMcb3; expires=Fri, 26-Apr-2013 06:53:36 GMT; path=/; domain=.google.com Date: Wed, 27 Apr 2011 06:53:36 GMT Server: gws Content-Length: 221 X-XSS-Protection: 1; mode=block <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.co.jp/">here</A>. </BODY></HTML> Connection closed by foreign host.
上記は,
GET / HTTP/1.0 (空行)
というのが,
それに対して,
HTTP/1.0 302 Found
というレスポンスが返ってきています。これはかいつまんで言うと,
Locationヘッダを見てみると,
Location: http://www.google.co.jp/
とありますので,
HTTP/1.1での接続(1)
次に,
$ telnet www.google.com 80 Trying 64.233.183.99... Connected to www.google.com (64.233.183.99). Escape character is '^]'. GET / HTTP/1.1 HOST: www.google.com HTTP/1.1 302 Found Location: http://www.google.co.jp/ Cache-Control: private Content-Type: text/html; charset=UTF-8 Set-Cookie: PREF=ID=7eab6b7eed7f7842:FF=0:TM=1303887994:LM=1303887994:S=4XH2bEZxD6t-DcEL; expires=Fri, 26-Apr-2013 07:06:34 GMT; path=/; domain=.google.com Date: Wed, 27 Apr 2011 07:06:34 GMT Server: gws Content-Length: 221 X-XSS-Protection: 1; mode=block <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.co.jp/">here</A>. </BODY></HTML>
ほとんど同じ内容になっていますが微妙に違います。
GET / HTTP/1.1 HOST: www.google.com (空行)
が,
レスポンスもほとんど一緒ですが,
ちなみにこういう場合, というプロンプトになるので, さらに続いて, 今回の例では, という内容をリクエストとして送っています。すると, この例で重要なのは, 今回は非常にざっくりですが, telnet>
HTTP/
$ telnet www.google.com 80
Trying 64.233.183.105...
Connected to www.google.com (64.233.183.105).
Escape character is '^]'.
GET / HTTP/1.1
HOST: www.google.com
Connection: close
HTTP/1.1 302 Found
Location: http://www.google.co.jp/
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=a967b73bc9b997b2:FF=0:TM=1303888386:LM=1303888386:S=xpUUMjtShIblnhJM; expires=Fri, 26-Apr-2013 07:13:06 GMT; path=/; domain=.google.com
Date: Wed, 27 Apr 2011 07:13:06 GMT
Server: gws
Content-Length: 221
X-XSS-Protection: 1; mode=block
Connection: close
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.jp/">here</A>.
</BODY></HTML>
Connection closed by foreign host.
GET / HTTP/1.1
HOST: www.google.com
Connection: close
(空行)