TLで「そもそもWebとかHTTPとはなんぞや?」みたいな話題を見かけたので。
こんなページを返す"Webサービス"があるとして…
Webブラウザはものすごーく大雑把にいうとこんなリクエストを発行してます。
[mazgi@Ardbeg] $ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET / HTTP/1.0
HTTP/1.1 200 OK
Date: Sun, 21 Jul 2013 13:57:02 GMT
Server: Apache/2.2.22 (Unix) DAV/2 mod_ssl/2.2.22 OpenSSL/0.9.8x
Content-Location: index.html.en
Vary: negotiate
TCN: choice
Last-Modified: Fri, 28 Dec 2012 12:23:10 GMT
ETag: "35d4b-2c-4d1e8b9ffa780"
Accept-Ranges: bytes
Content-Length: 44
Connection: close
Content-Type: text/html
Content-Language: en
<html><body><h1>It works!</h1></body></html>Connection closed by foreign host.
最後の1行にインデント入れてみると見慣れたHTMLソースになりますね♪
<html>
<body>
<h1>It works!</h1>
</body>
</html>
いちいち telnet
コマンド叩くのも手間だと思うので curl
オススメ。
(-v
または --verbose
付けましょう)
[mazgi@Ardbeg] $ curl -v localhost
* About to connect() to localhost port 80 (#0)
* Trying ::1...
* connected
* Connected to localhost (::1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8x zlib/1.2.5
> Host: localhost
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 21 Jul 2013 14:05:28 GMT
< Server: Apache/2.2.22 (Unix) DAV/2 mod_ssl/2.2.22 OpenSSL/0.9.8x
< Content-Location: index.html.en
< Vary: negotiate
< TCN: choice
< Last-Modified: Fri, 28 Dec 2012 12:23:10 GMT
< ETag: "35d4b-2c-4d1e8b9ffa780"
< Accept-Ranges: bytes
< Content-Length: 44
< Content-Type: text/html
< Content-Language: en
<
* Connection #0 to host localhost left intact
<html><body><h1>It works!</h1></body></html>* Closing connection #0