Curl工具简介

介绍


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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值