curl
コマンドラインからHTTPの確認をしたかったので「curl」をインストールしました。
インストール
xxx:~$ s apt-get install curl 以下の特別パッケージがインストールされます: libcurl3 以下のパッケージが新たにインストールされます: curl libcurl3 アップグレード: 0 個、新規インストール: 2 個、削除: 0 個、保留: 1 個。 取得:1 http://jp.archive.ubuntu.com gutsy/main libcurl3 7.16.4-2ubuntu1 [182kB] 取得:2 http://jp.archive.ubuntu.com gutsy/main curl 7.16.4-2ubuntu1 [175kB] libcurl3 (7.16.4-2ubuntu1) を設定しています ... curl (7.16.4-2ubuntu1) を設定しています ... Processing triggers for libc6 ... ldconfig deferred processing now taking place
相変わらず「Ubuntu」でのインストールは簡単です。
簡単な使い方
- 標準出力へレスポンスが返ります。
xxx:~$ curl http://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML>
- -O ファイル保存(curl -O http://google.com/index.html)。ファイル名を指定しないと保存されません。確認なしで上書きされます。
xxx:~$ curl -O http://google.com/index.html
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 229 100 229 0 0 575 0 --:--:-- --:--:-- --:--:-- 0
- -o 出力ファイル指定(curl -o test.html http://google.com)。こちらはファイル名がなくても大丈夫です。
xxx:~$ $curl -o test.html http://google.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 219 100 219 0 0 407 0 --:--:-- --:--:-- --:--:-- 0
- -L URLのリダイレクト対応(curl -L http://google.com)。リダイレクト先のレスポンスを返します。
- -u 認証ページ対応(curl -u userid:password http://example.com)。ユーザIDとパスワードを要求するページの場合に指定します。
- -v verbose指定(curl -v http://google.com)
xxx:~$ $curl -v http://google.com
* About to connect() to google.com port 80 (#0) * Trying 64.233.187.99... connected * Connected to google.com (64.233.187.99) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.16.4 (i486-pc-linux-gnu) libcurl/7.16.4 OpenSSL/0.9.8e zlib/1.2.3.3 libidn/1.0 > Host: google.com > Accept: */* > < HTTP/1.1 301 Moved Permanently < Location: http://www.google.com/ < Set-Cookie: PREF=ID=e7ad0a3ee4db3c68:TM=1210134600:LM=1210134600:S=fuPn-DjQY5uA6d5E; expires=Fri, 07-May-2010 04:30:00 GMT; path=/; domain=.google.com < Date: Wed, 07 May 2008 04:30:00 GMT < Content-Type: text/html; charset=UTF-8 < Server: gws < Content-Length: 219 < <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="http://www.google.com/">here</A>. </BODY></HTML> * Connection #0 to host google.com left intact * Closing connection #0
参考
こちら(→http://www.big.or.jp/~crane/cocoa/0800_internet/curl/)のページを参考にさせていただきました。もっと詳しい説明があります。