info
-
command line tool and library for transferring data with url syntax
-
supporting
dict, file, ftp, ftps, gopher, http, https, imap, imaps, ldap, ldaps, pop3, pop3s, rtmp, rtsp, scp, sftp, smb, smtp, smtps, telnet, tftp
-
supports ssl certificates
-
uploading
http post, http put, ftp, http form based
-
proxies, http/2, cookies, user+password authentication
basic, plain, digest, cram-md5, ntlm, negotiate and kerberos
-
file transfer resume
-
proxy tunneling
-
used for
in cars, television sets, routers, printers, audio equipment, mobile phones, tablets, settop boxes, media players
demo
-
http scripting
-
show everything curl sends and receives
$ curl --trace-ascii debug.txt http://www.baidu.com/
-
see timing
$ curl --trace-ascii debug.txt --trace-time http://www.baidu.com/
-
-
url
-
point out a different ip for a
host
name$ curl --resolve www.baidu.com:80:127.0.0.1 http://www.baidu.com/
-
specify the
port
number in the url$ curl http://www.baidu.com:1234/ # specify proxy's port number $ curl --proxy http://proxy.com:4321 http://www.baidu.com/
-
username and password
$ curl http://username:password@baidu.com/ $ curl -u username:password http://baidu.com/
-
-
fetch a page
-
get
$ curl http://www.baidu.com
-
multiple urls
$ curl http://www.baidu.com http://www.google.com # send two posts curl --data name=curl http://www.baidu.com http://www.google.com
-
multiple http methods
# send first a head # send second a get $ curl -l http://www.baidu.com --next http://www.google.com # send first a post # send second a get curl -d score=10 http://example.com/post.cgi --next http://example.com/results.html
-
-
html forms
-
get
<form method="GET" action="junk.cgi"> <input type=text name="birthyear"> <input type=submit name=press value="OK"> </form> $ curl "http://www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK"
-
post
<form method="POST" action="junk.cgi"> <input type=text name="birthyear"> <input type=submit name=press value=" OK "> </form> $ curl --data "birthday=1905&press=%20OK%20" http://www.example.com/when.cgi
-
file upload post
<form method="POST" enctype='multipart/form-data' action="upload.cgi"> <input type=file name=upload> <input type=submit name=press value="OK"> </form> $ curl --form upload=@localfilename --form press=OK url
-
hidden fields
<form method="POST" action="foobar.cgi"> <input type=text name="birthyear"> <input type=hidden name="person" value="daniel"> <input type=submit name="press" value="OK"> </form> $ curl --data "birthday=1905&press=OK&person=daniel" url
-
-
http upload
-
put
$ curl --upload-file uploadfile http://www.example.com/receive.cgi
-
-
http authentication
-
basic authentication
$ curl --user username:password http://www.example.com
-
other authentication
-
proxy authentication
$ curl --proxy-user proxyuser:password curl.haxx.se
-
-
more http headers
-
referer (misspelled)
$ curl --referer http://www.example.com http://www.example.com
-
user agent
# ie 5 on a Windows 2000 box: $ curl --user-agent "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" url # Netscape 4.73 on an old Linux box: curl --user-agent "Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)" url
-
-
redirects
-
location header
# tell curl to follow a location $ curl --location http://www.example.com
-
-
cookies
-
cookies options
$ curl --cookies "name=daniel" http://example.com # record cookies $ curl --dump-header header_and_cookies http://www.example.com # use previously stored cookies $ curl --cookies stored_cookies_in_file http://www.example.com # want curl to understand received cookies $ curl --cookies nada --location http://www.example.com # read and write cookies files $ curl --cookies cookies.txt --cookies-jar newcookies.txt http://www.example.com
-
-
https
-
https is http secure
$ curl https://secure.example.com
-
certificates
$ curl --cert mycert.pem https://secure.example.com $ curl --cert ca-bundle.pem https://example.com
-
-
custom request elements
-
modify method and headers
$ curl --data "<xml>" --header "Content-Type: text/xml" --request PROPFIND url.com # delete a default header by providing one without content $ curl --header "Host:" http://www.example.com # add header the same way $ curl --header "Destination: http://nowhere" http://example.com
-