transfer a URL : a tool to transfer data from or to a server, using one of the supported protocols
References
curl baidu.com # Output from url
curl -o tmp.html baidu.com # Write to file
# -o file : Write output to file
# -o = --output
curl -I icehe.life # Print only Headers
curl -i icehe.life # Print include Headers
# -I | --head : Fetch the headers only
# -i | --include : Include HTTP response headers
curl -s -X POST -H "Foo: bar" icehe.life
# -s | --silent : Do not show progress meter or error messages
# -X | --request : Specify request method
# -H | --header : Add a header
curl -LO https://raw.githubusercontent.com/IceHe/lib/master/README.md
# -L | --location : Enable redirect
# -O : Write local file named like remote file
# 指定 HTTP 请求的域名和 IP 地址
# e.g.
curl --resolve example.com:80:192.168.1.100 http://example.com/path
curl --resolve example.com:443:192.168.1.100 https://example.com/pathHeader
-I, --headFetch headers only! ( HTTP FTP FILE )-i, --includeInclude the HTTP-header in the output.-H, --header <header>Extra header to include in the request- when sending HTTP to a server ( HTTP )
- e.g.,
curl -H "X-First-Name: Joe" http://example.com/
Method
-X, --request <command>Specify a custom request method to use- when communicating with the HTTP server
- e.g.,
curl -X HEAD http://example.com/
Display
-s, --silentSilent or quiet mode.- Do not show progress meter or error messages.
-S, --show-errorIt makes curl show an error message if it fails.- when used with
-s, --silent
- when used with
Download
-L, --locationEnable redirect ( HTTP ) :- If the server reports that requested page has moved to different location (indicated with Location: header & 3XX response code), it will make curl redo the request on the new place.
-O, --remote-nameWrite output to local file named like remote file.- (Only file part of remote file is used, path is cut off.)
curl -LO <url_to_file>
# e.g.
$ curl -LO https://getcomposer.org/composer.phar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1841k 100 1841k 0 0 449k 0 0:00:04 0:00:04 --:--:-- 449kcurl -X <http_method> <url> -H '<header_name>: <header_value>'
# e.g.
$ curl -X POST http://10.1.2.3:8888/comments -H 'Host: api.weibo.cn'