curl base
下载
指定下载文件名,已存在同名文件被覆盖
curl -o filename.ext downloadlink
继续现有下载
curl -O -C downloadlink
检测下载文件是否存在,不下载
curl -I https://www.booleanworld.com/
自动重定向
curl -L http://example.com
最多700次重定向
curl -L --max-redirs 700 example.com
无限次
curl -L --max-redirs -1 example.com
cURL can only follow redirects if the server replied with a HTTP redirect
, which means that the server used a 3XX
status code, and it used the Location
header to indicate the new URL
查看res http header
curl -i http://example.com
verbose mode
curl -v http://example.com
-
the output contains request data (marked with
>
) -
response headers (marked with
<
) -
other details about the request, such as the IP used and the SSL handshake process (marked with
*
).
忽略res body
curl -vo /dev/null https://www.booleanworld.com/ # Linux/MacOS
curl -vo NUL https://www.booleanworld.com/ # Windows
忽略进度条以及错误
curl -svo /dev/null https://www.booleanworld.com/ # Linux/MacOS
curl -svo NUL https://www.booleanworld.com/ # Windows
忽略进度条,保留错误
curl -sSvo /dev/null https://www.booleanworld.com/ # Linux/MacOS
curl -sSvo NUL https://www.booleanworld.com/ # Windows
只忽略进度条,其他信息保存到文件
curl -sSvo file.html https://www.booleanworld.com/
处理错误
访问网站出错时,curl返回0
curl https://www.booleanworld.com/404 -sSo file.txt
访问网站出错时,curl返回非0
curl https://www.booleanworld.com/404 -fsSo file.txt
检测协议版本
curl -v --tlsv1.2 https://www.booleanworld.com/
curl -v --sslv3 https://www.booleanworld.com/
--sslv<version>
--tlsv<version>
--http1.0
--http1.1
--http2
时间
curl https://www.baidu.com/ -sSo /dev/null -w 'namelookup:\t%{time_namelookup}\nconnect:\t%{time_connect}\nappconnect:\t%{time_appconnect}\npretransfer:\t%{time_pretransfer}\nredirect:\t%{time_redirect}\nstarttransfer:\t%{time_starttransfer}\ntotal:\t\t%{time_total}\n'
namelookup — The time required for DNS resolution.
connect — The time required to establish the TCP connection.
appconnect — This is the time taken to establish connections for any layers between TCP and the application layer, such as SSL/TLS. In our case, the application layer is HTTP. Also, if there is no such intermediate layer (such as when there is a direct HTTP request), this time will always be 0.
pretransfer — This is the time taken from the start to when the transfer of the file is just about to begin.
redirect — This is the total time taken to process any redirects.
starttransfer — Time it took from the start to when the first byte is about to be transferred.
total — The total time taken for cURL to complete the entire process.