telnet で http

2011年9月15日木曜日

http telnet その他IT

t f B! P L

単に生死確認等が目的でレスポンスを見たいだけなら HTTP/1.0 でリクエスト。 リクエストの最後には空行を送ってやらないとレスポンス返ってきませんので注意。

$ telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.1 200 OK
Date: Sat, 17 Sep 2011 06:11:48 GMT
Server: Apache/2.0.64 (Unix) PHP/5.3.5
X-Powered-By: PHP/5.3.5
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 536
Connection: close
Content-Type: text/html
(省略)

特定のヘッダの挙動を見たい等で HTTP/1.1 でリクエストする場合には、Host ヘッダが必須になるので注意。 Host を忘れると、少なくとも Apache は 400 Bad Request ではじいてきます。 また、Connection: close を指定しておかないとサーバの設定によっては keep-alive されるので書きましょう。

$ telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
GET / HTTP/1.1
Host: 127.0.0.1
Connection: close

HTTP/1.1 200 OK
Date: Sat, 17 Sep 2011 06:19:01 GMT
Server: Apache/2.0.64 (Unix) PHP/5.3.5
X-Powered-By: PHP/5.3.5
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 536
Connection: close
Content-Type: text/html
(省略)

このブログを検索

ブログ アーカイブ

QooQ