介绍
curl是一个利用URL语法在命令行下工作的文件传输工具,1997年首次发行。它支持文件上传和下载,所以是综合传输工具。但按传统,习惯称cURL为下载工具。cURL还包含了用于程序开发的libcurl。
curl支持的通信协议有FTP、FTPS、HTTP、HTTPS、TFTP、SFTP、Gopher、SCP、Telnet、DICT、FILE、LDAP、LDAPS、IMAP、POP3、SMTP和RTSP。
Linux系统下自带命令,如果是Windows系统,需要额外下载。(https://curl.se/windows)
下载后解压至任意目录,添加【安装目录\curl-7.75.0-win64-mingw\bin】至环境变量path中。启动cmd命令行窗体,输入curl,出现【curl: try 'curl --help' for more information】即表示安装成功。
简单使用
常用命令如下:
C:\Users\xhh>curl --help
Usage: curl [options...] <url>
--abstract-unix-socket <path> Connect via abstract Unix domain socket
--anyauth Pick any authentication method
-a, --append Append to target file when uploading
--basic Use HTTP Basic Authentication
--cacert <CA certificate> CA certificate to verify peer against
--capath <dir> CA directory to verify peer against
-E, --cert <certificate[:password]> Client certificate file and password
--cert-status Verify the status of the server certificate
--cert-type <type> Certificate file type (DER/PEM/ENG)
--ciphers <list of ciphers> SSL ciphers to use
--compressed Request compressed response
#不带任何参数,就是发出GET请求。服务器返回内容在命令行显示。
C:\Users\xhh>curl www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css>省略……</div> </div> </div> </body> </html>
#使用 -o 参数将服务器响应保存成文件
C:\Users\xhh>curl -o baidu.html www.baidu.com
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2381 100 2381 0 0 2381 0 0:00:01 --:--:-- 0:00:01 51760
#使用 -O 参数下载指定文件
C:\Users\xhh\curl-test>curl -O http://www.baidu.com/test.JPG
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 206 100 206 0 0 206 0 0:00:01 --:--:-- 0:00:01 6645
#如果文件名相同,后缀不同的可以批量下载
C:\Users\xhh\curl-test>curl -O http://www.baidu.com/test[1-5].JPG
#使用 -d,已POST方式传输数据
#使用 -b,向服务器发送Cookie
#更多使用请参考: https://catonmat.net/cookbooks/curl
本文介绍了curl工具,它是1997年发行的命令行文件传输工具,支持多种通信协议,传统上被称为下载工具,还包含libcurl用于程序开发。Linux系统自带该命令,Windows需额外下载并配置环境变量。此外,还提及了简单使用的常用命令。

4284

被折叠的 条评论
为什么被折叠?



