例句:
for i in `seq 100`;do curl -s -o /dev/null http://www.2ycp.com/ -x ip:80 -w "time_total:"%{time_total}"\n";done|awk -F':' '{sum+=$2;count++}END{print sum/count}'
curl 'http://ip:port/sina.cdn.com.cn/v4/redirecthtml?uri=http://video.sina.com.cn/vod/hotgirl.flv' -H host:www.sina.com.cn --trace-ascii - -o /dev/null|head -n 38
curl是一个利用URL语法在命令行方式下工作的文件传输工具。它支持很多协议:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT, FILE 以及 LDAP。curl同样支持HTTPS认证,HTTP POST方法, HTTP PUT方法, FTP 上传, kerberos认证, HTTP上传, 代理服务器, cookies, 用户名/密码认证, 下载文件断点续传, 上载文件断点续传, http代理服务器管道( proxy tunneling), 甚至它还支持IPv6, socks5代理服务器, 通过http代理服务器上传文件 到FTP服务器等等,功能十分强大。Windows操作系统下的网络蚂蚁,网际快车(FlashGet)的功能它都可以做到。准确的说,curl支
持文件的上传和下载,所以是一个综合传输工具,但是按照传统,用户习惯称curl为下载工具。
curl是瑞典curl组织开发的,您可以访问http://curl.haxx.se/获取它的源代码和相关说明。鉴于curl在Linux上的广泛使用,IBM在AIX Linux Toolbox的光盘中包含了这个软件,并且您可以访问IBM网站http://www- 1.ibm.com/servers/aix/products/aixos/linux/altlic.html下载它。curl的最新版本是 7.10.8,IBM网站上提供的版本为7.9.3。在AIX下的安装很简单,IBM网站上下载的rpm格式的包。
在http://curl.haxx.se/docs/,您可以下载到UNIX格式的man帮助,里面有详细的curl工具的使用说明。curl的用法为:curl [options] [URL...] 其中options是下载需要的参数,大约有80多个,curl的各个功能完全是依靠这些参数完成的。具体参数的使用,用户可以参考curl的man帮助。
下面,本文就将结合具体的例子来说明怎样利用curl进行下载。
1、获得一张页面
使用命令:curl http://curl.haxx.se
这是最简单的使用方法。用这个命令获得了http://curl.haxx.se指向的页面,同样,如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地。如果下载的是HTML文档,那么缺省的将不显示文件头部,即HTML文档的header。要全部显示,请加参数 -i,要只显示头部,用参数 -I。任何时候,可以使用 -v 命令看curl是怎样工作的,它向服务器发送的所有命令都会显示出来。为了断点续传,可以使用-r参数来指定传输范围。
2、表单(Form)的获取
在WEB页面设计中,form是很重要的元素。Form通常用来收集并向网站提交信息。提交信息的方法有两种,GET方法和POST方法。先讨论GET方法,例如在页面中有这样一段:
那么浏览器上会出现一个文本框和一个标为“OK”的按钮。按下这个按钮,表单就用GET方法向服务器提交文本框的数据。例如原始页面是在 www.hotmail.com/when/birth.html看到的,然后您在文本框中输入1905,然后按OK按钮,那么浏览器的URL现在应该 是:“www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK”
对于这种网页,curl可以直接处理,例如想获取上面的网页,只要输入:
curl "www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK"
就可以了。
表单用来提交信息的第二种方法叫做POST方法,POST方法和GET方法的区别在于GET方法使用的时候,浏览器中会产生目标URL,而POST不会。类似GET,这里有一个网页:
浏览器上也会出现一个文本框和一个标为“OK”的按钮。按下这个按钮,表单用POST方法向服务器提交数据。这时的URL是看不到的,因此需要使用特殊的方法来抓取这个页面:
curl -d "birthyear=1905&press=OK" www.hotmail.com/when/junk.cgi
这个命令就可以做到。
1995年年末,RFC 1867定义了一种新的POST方法,用来上传文件。主要用于把本地文件上传到服务器。此时页面是这样写的:
对于这种页面,curl的用法不同:
curl -F upload=@localfilename -F press=OK [URL]
这个命令的实质是将本地的文件用POST上传到服务器。有关POST还有不少用法,用户可以自己摸索。
3、使用PUT方法。
HTTP协议文件上传的标准方法是使用PUT,此时curl命令使用-T参数:
curl -T uploadfile www.uploadhttp.com/receive.cgi
4、有关认证。
curl可以处理各种情况的认证页面,例如下载用户名/密码认证方式的页面(在IE中通常是出现一个输入用户名和密码的输入框):
curl -u name:password www.secrets.com
如果网络是通过http代理服务器出去的,而代理服务器需要用户名和密码,那么输入:
curl -U proxyuser:proxypassword http://curl.haxx.se
任何需要输入用户名和密码的时候,只在参数中指定用户名而空着密码,curl可以交互式的让用户输入密码。
5、引用。
有些网络资源访问的时候必须经过另外一个网络地址跳转过去,这用术语来说是:referer,引用。对于这种地址的资源,curl也可以下载:
curl -e http://curl.haxx.se daniel.haxx.se
6、指定用户客户端。
有些网络资源首先需要判断用户使用的是什么浏览器,符合标准了才能够下载或者浏览。此时curl可以把自己“伪装”成任何其他浏览器:
curl -A "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" [URL]
这个指令表示curl伪装成了IE5.0,用户平台是Windows 2000。(对方服务器是根据这个字串来判断客户端的类型的,所以即使使用AIX也无所谓)。使用:
curl -A "Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)" [URL]
此时curl变成了Netscape,运行在PIII平台的Linux上了。
7、COOKIES
Cookie是服务器经常使用的一种记忆客户信息的方法。如果cookie被记录在了文件中,那么使用命令:
curl -b stored_cookies_in_file www.cookiesite.com
curl可以根据旧的cookie写出新cookie并发送到网站:
curl -b cookies.txt -c newcookies.txt www.cookiesite.com
8、加密的HTTP——HTTPS。
如果是通过OpenSSL加密的https协议传输的网页,curl可以直接访问:
curl https://that.secure.server.com
9、http认证。
如果是采用证书认证的http地址,证书在本地,那么curl这样使用:
curl -E mycert.pem https://that.secure.server.com
参考读物和注意事项:curl非常博大,用户要想使用好这个工具,除了详细学习参数之外,还需要深刻理解http的各种协议与URL的各个语法。这里推荐几个读物:
RFC 2616 HTTP协议语法的定义。
RFC 2396 URL语法的定义。
RFC 2109 Cookie是怎样工作的。
RFC 1867 HTTP如何POST,以及POST的格式
#############################################################
CURL? 嗯,说来话长了~~~~这东西现在已经是苹果机上内置的命令行工具之一了,可见其魅力之一斑
1)
二话不说,先从这里开始吧!
curl http://www.yahoo.com
回车之后,www.yahoo.com 的html就稀里哗啦地显示在屏幕上了~~~~~
2)
嗯,要想把读过来页面存下来,是不是要这样呢?
curl http://www.yahoo.com > page.html
当然可以,但不用这么麻烦的!
用curl的内置option就好,存下http的结果,用这个option: -o
curl -o page.html http://www.yahoo.com
这样,你就可以看到屏幕上出现一个下载页面进度指示。等进展到100%,自然就OK咯
3)
什么什么?!访问不到?肯定是你的proxy没有设定了。
使用curl的时候,用这个option可以指定http访问所使用的proxy服务器及其端口: -x
curl -x 123.45.67.89:1080 -o page.html http://www.yahoo.com
4)
访问有些网站的时候比较讨厌,他使用cookie来记录session信息。
像IE/NN这样的浏览器,当然可以轻易处理cookie信息,但我们的curl呢?
..
我们来学习这个option: -D <-- 这个是把http的response里面的cookie信息存到一个特别的文件中去
curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com
这样,当页面被存到page.html的同时,cookie信息也被存到了cookie0001.txt里面了
5)
那么,下一次访问的时候,如何继续使用上次留下的cookie信息呢?要知道,很多网站都是靠监视你的cookie信息,
来判断你是不是不按规矩访问他们的网站的。
这次我们使用这个option来把上次的cookie信息追加到http request里面去: -b
curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.yahoo.com
这样,我们就可以几乎模拟所有的IE操作,去访问网页了!
6)
稍微等等~~~~~我好像忘记什么了~~~~~
对了!是浏览器信息~~~~
有些讨厌的网站总要我们使用某些特定的浏览器去访问他们,有时候更过分的是,还要使用某些特定的版本~~~~
NND,哪里有时间为了它去找这些怪异的浏览器呢!?
好在curl给我们提供了一个有用的option,可以让我们随意指定自己这次访问所宣称的自己的浏览器信息: -A
curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.yahoo.com
这样,服务器端接到访问的要求,会认为你是一个运行在Windows 2000上的IE6.0,嘿嘿嘿,其实也许你用的是苹果机呢!
而"Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686"则可以告诉对方你是一台PC上跑着的Linux,用的是Netscape 4.73,呵呵呵
7)
另 外一个服务器端常用的限制方法,就是检查http访问的referer。比如你先访问首页,再访问里面所指定的下载页,这第二次访问的referer地址 就是第一次访问成功后的页面地址。这样,服务器端只要发现对下载页面某次访问的referer地址不 是首页的地址,就可以断定那是个盗连 了~~~~~
讨厌讨厌~~~我就是要盗连~~~~~!!
幸好curl给我们提供了设定referer的option: -e
curl -A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" -x 123.45.67.89:1080 -e "mail.yahoo.com" -o page.html -D cookie0001.txt http://www.yahoo.com
这样,就可以骗对方的服务器,你是从mail.yahoo.com点击某个链接过来的了,呵呵呵
8)
写着写着发现漏掉什么重要的东西了!----- 利用curl 下载文件
刚才讲过了,下载页面到一个文件里,可以使用 -o ,下载文件也是一样。
比如, curl -o 1.jpg http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
这里教大家一个新的option: -O
大写的O,这么用: curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
这样,就可以按照服务器上的文件名,自动存在本地了!
再来一个更好用的。
如果screen1.JPG以外还有screen2.JPG、screen3.JPG、
.、screen10.JPG需要下载,难不成还要让我们写一个script来完成这些操作?
不干!
在curl里面,这么写就可以了:
curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG
呵呵呵,厉害吧?!~~~
9)
再来,我们继续讲解下载!
curl -O http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG
这样产生的下载,就是
~zzh/001.JPG
~zzh/002.JPG
~zzh/201.JPG
~nick/001.JPG
~nick/002.JPG
~nick/201.JPG
够方便的了吧?哈哈哈
咦?高兴得太早了。
由于zzh/nick下的文件名都是001,002
,201,下载下来的文件重名,后面的把前面的文件都给覆盖掉了~~~
没关系,我们还有更狠的!
curl -o #2_#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG
--这是
..自定义文件名的下载?
--对头,呵呵!
#1是变量,指的是{zzh,nick}这部分,第一次取值zzh,第二次取值nick
#2代表的变量,则是第二段可变部分---[001-201],取值从001逐一加到201
这样,自定义出来下载下来的文件名,就变成了这样:
原来: ~zzh/001.JPG ---> 下载后: 001-zzh.JPG
原来: ~nick/001.JPG ---> 下载后: 001-nick.JPG
这样一来,就不怕文件重名啦,呵呵
9)
继续讲下载
我们平时在windows平台上,flashget这样的工具可以帮我们分块并行下载,还可以断线续传。
curl在这些方面也不输给谁,嘿嘿
比如我们下载screen1.JPG中,突然掉线了,我们就可以这样开始续传
curl -c -O http://cgi2.tky.3wb.ne.jp/~zzh/screen1.JPG
当然,你不要拿个flashget下载了一半的文件来糊弄我~~~~别的下载软件的半截文件可不一定能用哦~~~
分块下载,我们使用这个option就可以了: -r
举例说明
比如我们有一个http://cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 要下载(赵老师的电话朗诵 :D )
我们就可以用这样的命令:
curl -r 0-10240 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &
curl -r 10241-20480 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &
curl -r 20481-40960 -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3 &
curl -r 40961- -o "zhao.part1" http:/cgi2.tky.3web.ne.jp/~zzh/zhao1.mp3
这样就可以分块下载啦。
不过你需要自己把这些破碎的文件合并起来
如果你用UNIX或苹果,用 cat zhao.part* > zhao.mp3就可以
如果用的是Windows,用copy /b 来解决吧,呵呵
上面讲的都是http协议的下载,其实ftp也一样可以用。
用法嘛,
curl -u name:passwd ftp://ip:port/path/file
或者大家熟悉的
curl ftp://name:passwd@ip:port/path/file
10)
说完了下载,接下来自然该讲上传咯
上传的option是 -T
比如我们向ftp传一个文件: curl -T localfile -u name:passwd ftp://upload_site:port/path/
当然,向http服务器上传文件也可以
比如 curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
注意,这时候,使用的协议是HTTP的PUT method
刚才说到PUT,嘿嘿,自然让老服想起来了其他几种methos还没讲呢!
GET和POST都不能忘哦。
http提交一个表单,比较常用的是POST模式和GET模式
GET模式什么option都不用,只需要把变量写在url里面就可以了
比如:
curl http://www.yahoo.com/login.cgi?user
&password=12345
而POST模式的option则是 -d
比如,curl -d "user=nickwolfe&password=12345" http://www.yahoo.com/login.cgi
就相当于向这个站点发出一次登陆申请~~~~~
到底该用GET模式还是POST模式,要看对面服务器的程序设定。
一点需要注意的是,POST模式下的文件上的文件上传,比如
<form method="POST" enctype="multipar/form-data" action="http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi">
<input type=file name=upload>
=submit name=nick value="go">
form>
这样一个HTTP表单,我们要用curl进行模拟,就该是这样的语法:
curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi
罗罗嗦嗦讲了这么多,其实curl还有很多很多技巧和用法
比如 https的时候使用本地证书,就可以这样
curl -E localcert.pem https://remote_server
再比如,你还可以用curl通过dict协议去查字典~~~~~
curl dict://dict.org/d:computer
######################################################################
首先得安装了curl库
查看参数
[mm@niutian365~]$ curl --help
Usage: curl [options...]
Options: (H) means HTTP/HTTPS only, (F) means FTP only
-a/--append Append to target file when uploading (F)
-A/--user-agent User-Agent to send to server (H)
--anyauth Pick "any" authentication method (H)
-b/--cookie Cookie string or file to read cookies from (H)
--basic Use HTTP Basic Authentication (H)
-B/--use-ascii Use ASCII/text transfer
-c/--cookie-jar Write cookies to this file after operation (H)
-C/--continue-at Resumed transfer offset
-d/--data HTTP POST data (H)
--data-ascii HTTP POST ASCII data (H)
--data-binary HTTP POST binary data (H)
--negotiate Use HTTP Negotiate Authentication (H)
--digest Use HTTP Digest Authentication (H)
--disable-eprt Inhibit using EPRT or LPRT (F)
--disable-epsv Inhibit using EPSV (F)
-D/--dump-header Write the headers to this file
--egd-file EGD socket path for random data (SSL)
--tcp-nodelay Use the TCP_NODELAY option
-e/--referer Referer URL (H)
-E/--cert Client certificate file and password (SSL)
--cert-type Certificate file type (DER/PEM/ENG) (SSL)
--key Private key file name (SSL)
--key-type Private key file type (DER/PEM/ENG) (SSL)
--pass Pass phrase for the private key (SSL)
--engine Crypto engine to use (SSL). "--engine list" for list
--cacert CA certificate to verify peer against (SSL)
--capath CA directory (made using c_rehash) to verify
peer against (SSL)
--ciphers SSL ciphers to use (SSL)
--compressed Request compressed response (using deflate or gzip)
--connect-timeout Maximum time allowed for connection
--create-dirs Create necessary local directory hierarchy
--crlf Convert LF to CRLF in upload
-f/--fail Fail silently (no output at all) on HTTP errors (H)
--ftp-create-dirs Create the remote dirs if not present (F)
--ftp-method [multicwd/nocwd/singlecwd] Control CWD usage (F)
--ftp-pasv Use PASV/EPSV instead of PORT (F)
--ftp-skip-pasv-ip Skip the IP address for PASV (F)
--ftp-ssl Try SSL/TLS for the ftp transfer (F)
--ftp-ssl-reqd Require SSL/TLS for the ftp transfer (F)
-F/--form Specify HTTP multipart POST data (H)
--form-string Specify HTTP multipart POST data (H)
-g/--globoff Disable URL sequences and ranges using {} and []
-G/--get Send the -d data with a HTTP GET (H)
-h/--help This help text
-H/--header Custom header to pass to server (H)
--ignore-content-length Ignore the HTTP Content-Length header
-i/--include Include protocol headers in the output (H/F)
-I/--head Show document info only
-j/--junk-session-cookies Ignore session cookies read from file (H)
--interface Specify network interface/address to use
--krb4 Enable krb4 with specified security level (F)
-k/--insecure Allow connections to SSL sites without certs (H)
-K/--config Specify which config file to read
-l/--list-only List only names of an FTP directory (F)
--limit-rate Limit transfer speed to this rate
--local-port [-num] Force use of these local port numbers
-L/--location Follow Location: hints (H)
--location-trusted Follow Location: and send authentication even
to other hostnames (H)
-m/--max-time Maximum time allowed for the transfer
--max-redirs Maximum number of redirects allowed (H)
--max-filesize Maximum file size to download (H/F)
-M/--manual Display the full manual
-n/--netrc Must read .netrc for user name and password
--netrc-optional Use either .netrc or URL; overrides -n
--ntlm Use HTTP NTLM authentication (H)
-N/--no-buffer Disable buffering of the output stream
-o/--output Write output to instead of stdout
-O/--remote-name Write output to a file named as the remote file
-p/--proxytunnel Operate through a HTTP proxy tunnel (using CONNECT)
--proxy-anyauth Pick "any" proxy authentication method (H)
--proxy-basic Use Basic authentication on the proxy (H)
--proxy-digest Use Digest authentication on the proxy (H)
--proxy-ntlm Use NTLM authentication on the proxy (H)
-P/--ftp-port
Use PORT with address instead of PASV (F)
-q If used as the first parameter disables .curlrc
-Q/--quote Send command(s) to server before file transfer (F)
-r/--range Retrieve a byte range from a HTTP/1.1 or FTP server
--random-file File for reading random data from (SSL)
-R/--remote-time Set the remote file's time on the local output
--retry Retry request times if transient problems occur
--retry-delay When retrying, wait this many seconds between each
--retry-max-time Retry only within this period
-s/--silent Silent mode. Don't output anything
-S/--show-error Show error. With -s, make curl show errors when they occur
--socks4 Use SOCKS4 proxy on given host + port
--socks5 Use SOCKS5 proxy on given host + port
--stderr Where to redirect stderr. - means stdout
-t/--telnet-option Set telnet option
--trace Write a debug trace to the given file
--trace-ascii Like --trace but without the hex output
--trace-time Add time stamps to trace/verbose output
-T/--upload-file Transfer to remote site
--url Spet URL to work with
-u/--user Set server user and password
-U/--proxy-user Set proxy user and password
-v/--verbose Make the operation more talkative
-V/--version Show version number and quit
-w/--write-out [format] What to output after completion
-x/--proxy Use HTTP proxy on given port
-X/--request Specify request command to use
-y/--speed-time Time needed to trig speed-limit abort. Defaults to 30
-Y/--speed-limit Stop transfer if below speed-limit for 'speed-time' secs
-z/--time-cond Transfer based on a time condition
-0/--http1.0 Use HTTP 1.0 (H)
-1/--tlsv1 Use TLSv1 (SSL)
-2/--sslv2 Use SSLv2 (SSL)
-3/--sslv3 Use SSLv3 (SSL)
--3p-quote like -Q for the source URL for 3rd party transfer (F)
--3p-url source URL to activate 3rd party transfer (F)
--3p-user user and password for source 3rd party transfer (F)
-4/--ipv4 Resolve name to IPv4 address
-6/--ipv6 Resolve name to IPv6 address
-#/--progress-bar Display transfer progress as a progress bar
使用 cURL 测试 Web 站点的响应时间
[mm@niutian365~]$ curl -o /dev/null -s -w %{time_connect}:%{time_starttransfer}:%{time_total} http://blog.niutian365.com 0.081:0.272:0.779
清单 1 给出对一个流行的新闻站点执行 curl 命令的情况。输出通常是 HTML 代码,通过 -o 参数发送到 /dev/null。-s 参数去掉所有状态信息。-w 参数让 curl 写出表 1 列出的计时器的状态信息:
表 1. curl 使用的计时器
计时器 描述
time_connect 建立到服务器的 TCP 连接所用的时间
time_starttransfer 在发出请求之后,Web 服务器返回数据的第一个字节所用的时间
time_total 完成请求所用的时间
这 些计时器都相对于事务的起始时间,甚至要先于 Domain Name Service(DNS)查询。因此,在发出请求之后,Web 服务器处理请求并开始发回数据所用的时间是 0.272 - 0.081 = 0.191 秒。客户机从服务器下载数据所用的时间是 0.779 - 0.272 = 0.507 秒。
通过观察 curl 数据及其随时间变化的趋势,可以很好地了解站点对用户的响应性。
当然,Web 站点不仅仅由页面组成。它还有图像、JavaScript 代码、CSS 和 cookie 要处理。curl 很适合了解单一元素的响应时间,但是有时候需要了解整个页面的装载速度。
#######################################################################
上网用 firefox ie @windows, lynx links @linux console
这些都存在较多的交互
分析交互让机器去做去模拟
这就是curl的作用
多种小工具通过接口 管道等整合
将发挥不可估量的作用
curl 是支持 http ftp 多种协议的工具 可以获取文件 传递文件
以一种快捷高效透明的方式进行信息的来去管理
其官方网址是 http://curl.haxx.se/
curl 能干什么
curl能干的事太多了
由于对大多协议都支持 所以curl几乎可以为所欲为
下载文件 上传文件 提交表单 ......
上面提到的正是的强项
由于是命令行接口 使得脚本调用 批量处理灵活运用极为方便
curl 就是对 URL 的革命
curl 怎么做
curl 提供了丰富的接口开关
具有支持代理 认证 断点续传等多种很不错的feature
curl 的返回让用户可以对发生了申请了如指掌
curl 是电 curl 是光 curl 是唯一的神话
curl 就是 super star
简要介绍一些接口参数
-A --user-agent 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'
-b --cookie "N1=V1;N2=V2" 不写=号 还能写到文件 是对 server Set-Cookie 的接纳
-D --dump-header 存 cookie
--connect-timeout 秒数 设置超时
-c --cookie-jar filename
-d --data (等同于 --data-ascii) -d user=windtear -d passwd=secret:P
-e --refer URL 设置 refer 有时候很有用哦
-F --form 它主要是对 multipart/form-data 进行处理(RFC1867) 如果加@为文件上传 如果用<文件名 则为正文当参数传 -F "file=@filename.ext;type=text/html"
-G --get 就是当 get 用 和 -d ...结合的时候 自动重组
-H --header 多头
-i --include 包括头 对了解服务器信息很有用
-I 只有头 也就是只有 HEAD 的处理
-m --max-time 秒数 不支持 win32
-N --no-buffer
-o --output file 支持 {a,b} [] 等 后面还可以用#1 #2 调用
-O 存远程名字 如果多URL 用多次
-R --remote-time 这是一个负负得正的函数
-s --silent 同样ffdz
--url
-v --verbose
-x --proxy proxyhost:port
-0 --http1.0 默认是HTTP/1.1 这样可以强制 HTTP/1.0
curl 的环境变量
http_proxy 等很有用 而且默认就用 除非用 -x "" 冲掉它
curl官方网站:
http://curl.haxx.se
最简单的用法:
获得netscape's 网站网页:
curl http://www.netscape.com/
在FTP服务器获得README文件:
curl ftp://ftp.funet.fi/README
获得一个使用8000端口的web服务器网页:
curl http://www.weirdserver.com:8000/
获得一个FTP目录的镜象:
curl ftp://cool.haxx.se/
获得一个gopher服务器上的文档:
curl gopher://gopher.funet.fi
获得自定义目录的文件:
curl dict://dict.org/m:curl
一次获得2个文档:
curl ftp://cool.haxx.se/ http://www.weirdserver.com:8000/
下载文件
将一个WEB页保存到硬盘上,名字叫thatpage.html:
curl -o thatpage.html http://www.netscape.com/
下载index.html文件, -O是大写的字母o。 (如果没有文件名,将会出现错误):
curl -O http://www.netscape.com/index.html
下载2个文件:
curl -O www.haxx.se/index.html -O curl.haxx.se/download.html
使用密码
FTP
ftp服务器使用 名字+密码, 可能包括他们的URL:
curl ftp://name:passwd@machine.domain:port/full/path/to/file
或者用-u指定名字和密码
curl -u name:passwd ftp://machine.domain:port/full/path/to/file
FTPS
你也可以使用SSL选项.
HTTP
HTTP的URL不支持名字+密码. 但Curl无论如何都支持ftp风格的接口。
curl http://name:passwd@machine.domain/full/path/to/file
或分别指定名字和密码,同样还是使用-u选项
curl -u name:passwd http://machine.domain/full/path/to/file
HTTP也许提供许多鉴别方法和 curl支持若干: 基础, Digest, NTLM 和 Negotiate. 没有哪个有效的使用方法, curl默认使用'基础'. 你可以询问curl以获得更多的保护。
任何服务器都会提供url, 使用
--anyauth.
注意! 自从HTTP URLs 不支持用户名和密码, 当curl使用一个代理的时候,你不能使用这个风格. 你必须使用-u选项来读取.
HTTPS
通常都用私人的证书, 说明如下.
GOPHER
Curl 没有密码支持gopher.
PROXY
使用端口888代理下载一个文件,代理地址是my-proxy:
curl -x my-proxy:888 ftp://ftp.leachsite.com/README
从一个http服务器下载一个文件,需要用户名和密码, 同样使用如上设置:
curl -u user:passwd -x my-proxy:888 http://www.get.this/
一些代理需要特别的验证. 用 -U 来设置:
curl -U user:passwd -x my-proxy:888 http://www.get.this/
See also the environment variables Curl support that offer further proxy
control.
RANGES
一个客户只能请求一个连接或更多的连接. Curl支持-r标记.
获得文件的前100 bytes:
curl -r 0-99 http://www.get.this/
获得文件的末尾500 bytes:
curl -r -500 http://www.get.this/
Curl 也支持简单的ftp文件. 你只能规定开始和停止的位置.
获得ftp服务器上的readme的前100 bytes:
curl -r 0-99 ftp://www.get.this/README
UPLOADING
FTP
一个命令上传全部数据:
curl -T - ftp://ftp.upload.com/myfile
往一个站点上上传数据, 并且使用名字和密码
curl -T uploadfile -u user:passwd ftp://ftp.upload.com/myfile
往站点上上传一个本地文件, 并且也使用本地文件名:
curl -T uploadfile -u user:passwd ftp://ftp.upload.com/
Upload a local file to get appended to the remote file using ftp:
curl -T localfile -a ftp://ftp.upload.com/remotefile
Curl也支持穿过代理上传数据, 但服务器要支持才可以. 如果不支持, you can run curl in
a fashion similar to:
curl --proxytunnel -x proxy:port -T localfile ftp.upload.com
HTTP
上传所有数据到一个http服务器:
curl -T - http://www.upload.com/myfile
注意:上传之前,你要确定HTTP服务器已给你上传的授权.
For other ways to do http data upload, see the POST section below.
VERBOSE / DEBUG
如果curl fails where it isn't supposed to, 如果服务器不让你进,
if you can't understand the responses: 使用 -v 标记获得详细报告. Curl将输出许多发送和接受的信息
order to let the user see all client-server interaction (but it won't show
you the actual data).
curl -v ftp://ftp.upload.com/
获得curl更多的信息和资料, 使用--trace 或 --trace-ascii 选项:
curl --trace trace.txt www.haxx.se
详细信息
不同的协议供应不同的信息参考关于files/documents. 获得curl的详细文件, 你应该使用 -I/--head option. 它得到全部的HTTP and FTP的详细信息. HTTP的参考很多.
For HTTP, you can get the header information (the same as -I would show)
shown before the data by using -i/--include. Curl understands the
-D/--dump-header option when getting files from both FTP and HTTP, and it
will then store the headers in the specified file.
Store the HTTP headers in a separate file (headers.txt in the example):
curl --dump-header headers.txt curl.haxx.se
Note that headers stored in a separate file can be very useful at a later
time if you want curl to use cookies sent by the server. More about that in
the cookies section.
REFERRER
A HTTP request has the option to include information about which address
that referred to actual page. Curl allows you to specify the
referrer to be used on the command line. It is especially useful to
fool or trick stupid servers or CGI scripts that rely on that information
being available or contain certain data.
curl -e www.coolsite.com http://www.showme.com/
NOTE: The referer field is defined in the HTTP spec to be a full URL.
USER AGENT
关于浏览器发送的http请求信息. Curl允许用命令制定. 发送一些用于欺骗服务器或cgi的信息.
比如:
curl -A 'Mozilla/3.0 (Win95; I)' http://www.nationsbank.com/
其他命令:
'Mozilla/3.0 (Win95; I)' Netscape Version 3 for Windows 95
'Mozilla/3.04 (Win95; U)' Netscape Version 3 for Windows 95
'Mozilla/2.02 (OS/2; U)' Netscape Version 2 for OS/2
'Mozilla/4.04 [en] (X11; U; AIX 4.2; Nav)' NS for AIX
'Mozilla/4.05 [en] (X11; U; Linux 2.0.32 i586)' NS for Linux
注意:Internet Explorer能自动调节:
'Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)' MSIE for W95
Mozilla 使用User-Agent名字:
'Konqueror/1.0' KDE File Manager desktop client
'Lynx/2.7.1 libwww-FM/2.14' Lynx command line browser
PROGRESS METER
The progress meter