我们要测试某个url是否有效,不需要把文件下载下来,只需要发送HEAD请求,获得文件头即可,下面是两种获取文件头的方式:
1.使用curl
- root@vs-3310-099:/var/lib/mysql# curl -X "HEAD" -v http://ftp.iij.ad.jp/pub/db/mysql/Downloads/MySQL-5.5/MySQL-client-5.5.14-1.linux2.6.x86_64.rpm
- * About to connect() to ftp.iij.ad.jp port 80 (#0)
- * Trying 202.232.140.135... connected
- * Connected to ftp.iij.ad.jp (202.232.140.135) port 80 (#0)
- > HEAD /pub/db/mysql/Downloads/MySQL-5.5/MySQL-client-5.5.14-1.linux2.6.x86_64.rpm HTTP/1.1
- > User-Agent: curl/7.19.7 (x86_64-pc-linux-gnu) libcurl/7.19.7 OpenSSL/0.9.8k zlib/1.2.3.3 libidn/1.15
- > Host: ftp.iij.ad.jp
- > Accept: */*
- >
- < HTTP/1.1 200 OK
- < Date: Wed, 13 Jul 2011 04:24:15 GMT
- < Server: Apache
- < Last-Modified: Tue, 05 Jul 2011 15:22:10 GMT
- < ETag: "3bafc115-10e92cd-c29cc80"
- < Accept-Ranges: bytes
- < Content-Length: 17732301
- < Connection: close
- < Content-Type: application/x-rpm
- <
- * transfer closed with 17732301 bytes remaining to read
- * Closing connection #0
- curl: (18) transfer closed with 17732301 bytes remaining to read
2.telnet
- root@vs-3310-099:/var/lib/mysql# telnet ftp.iij.ad.jp 80
- Trying 202.232.140.138...
- Connected to ftp.iij.ad.jp.
- Escape character is '^]'.
- HEAD /pub/db/mysql/Downloads/MySQL-5.5/MySQL-client-5.5.14-1.linux2.6.x86_64.rpm HTTP/1.1
- HOST: ftp.iij.ad.jp
- HTTP/1.1 200 OK
- Date: Wed, 13 Jul 2011 04:28:02 GMT
- Server: Apache
- Last-Modified: Tue, 05 Jul 2011 15:22:10 GMT
- ETag: "3bafc115-10e92cd-c29cc80"
- Accept-Ranges: bytes
- Content-Length: 17732301
- Connection: close
- Content-Type: application/x-rpm
- Connection closed by foreign host.