Detailed explanation of curl's v and 0 parameters

curl is a widely used command-line tool for uploading and downloading, but strictly speaking, it can also be used for other purposes. For testing, it is a very useful tool for Web-related testing, including debugging, which is very convenient to use. On the other hand, because it is a pure command line tool, it can also be easily integrated into automation or other testing frameworks as a component, and hand over HTTP/HTTPS/FTP related uploading and downloading tasks to it.
Recently, because I am doing web service related tests, I have used curl. I think it is not bad. By the way, I will introduce it to you.

official site: http://curl.haxx.se/ , the latest version is 7.20.0.

Basic usage example
curl http://www.google.com
curl -o f1 ftp://user:pwd@myftp/Ricky/test.ini
curl dict://dict.org/d:

test parameters, you can check its own help documentation for this aspect.
-V show the version of curl
C:/Tools/curl-7.20.0>curl -V
curl 7.20.0 (i386-pc-win32) libcurl/7.20.0 OpenSSL/0.9.8l zlib/1.2.3
Protocols: dict file ftp ftps http https imap imaps ldap pop3 pop3s rtsp smtp smtps telnet tftp
Features: AsynchDNS Largefile NTLM SSL SSPI libz


-o [filename], save content to a file
-O use the same name
curl -o g.html www.google.com
curl -O http://www.google.com/intl/en_ALL/images/logo.gif

-i, Include the HTTP-header in the output    
curl -i http://www.google.com
-u username:password
curl -u user:pwd ftp://myftp/Ricky/test.ini

-d parameters
curl http://www.yahoo.com/login.cgi?user=nick&password=12345
curl -d "user=nick&password=12345" http://www.yahoo.com/login.cgi

-x  proxy_ip:port, access with proxy
curl -i -x myproxy:8080 -o google_proxy.html http://www.google.com

HTTP/1.1 302 Found
Via: 1.0 myproxy
Content-Length: 222
Date: Mon, 22 Mar 2010 14:15:48 GMT
Location: http://www.google.com.tw/
Content-Type: text/html; charset=UTF-8
Cache-Control: private
Set-Cookie: PREF=ID=aa97c3734c862ddf:TM=1269267348:LM=1269267348:S=4FEEGAPNu2FN2lho; expires=Wed, 21-Mar-2012 14:15:48 GMT; path=/; domain=.google.com
Set-Cookie: NID=32=MXKkZjgjiNGVNnPv9w384COa2KJZOLu5v9_5coX_N1tJtaa97-dJUxb7DCz90vQsm0fLEPg0Ee3nXv1yDDcE3ZN0sOu7mq9-mjB9CL0okXGjiIvox2FTcw0HBV7hBaLC; expires=Tue, 21-Sep-2010 14:15:48 GMT; path=/; domain=.google.com; HttpOnly
Server: gws
X-XSS-Protection: 0

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.com.tw/">here</A>.
</BODY></HTML>

-r [start-end], such as "-r 0-1024"
curl -i -r 0-1024 -o rfc1.txt http://xml.resource.org/public/rfc/bibxml3/rdf/item.I-D.6man-pmip6-ind.rdf
header:
HTTP/1.1 206 Partial Content
Date: Mon, 22 Mar 2010 13:50:46 GMT
Server: Apache/2.2.15 (Debian)
Last-Modified: Mon, 09 Mar 2009 23:02:11 GMT
ETag: "148be6-466-464b79fe1a2c0"
Accept-Ranges: bytes
Content-Length: 1025
Content-Range: bytes 0-1024/1126
Content-Type: application/rdf+xml

note: not all web server support partial content, or it will response all even you try to get part
curl -i -r 0-1024 http://www.sina.com.cn -o sina_part1.htm
it will give you all the page.

-k insecure SSL , will not check the cert
curl -k https://ip:8445

-T upload a file with FTP
curl -T curl.html -u user:pwd ftp://myftp/Ricky/
execute once again will overwrite

-F/--form <name=content>, use for http post
curl -F password=@/etc/passwd www.mypasswords.com
You can also tell curl what Content-Type to use by using 'type=', in a manner similar to:
curl -F "[email protected];type=text/html" url.com

转自:http://blog.csdn.net/superqa/article/details/5418636

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326957227&siteId=291194637