curl 大杂烩 合集
cURL百科
cURL是一个开源项目,主要的产品是curl(命令行工具)和libcurl(C语言的API库),两者功能均是:基于网络协议,对指定URL进行网络传输。
cURL涉及是任何网络协议传输,不涉及对具体数据的具体处理。curl支持的通信协议有DICT, FILE, FTP, FTPS, GOPHER, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SBMS, SMTP, SMTPS, TELNET 和TFTP。
cURL 官方网站
https://curl.se/
cURL 例子
cURL 简单模式:
$ curl http://example.com
cURL 详细(verbose)模式:
$ curl --verbose http://example.com
$ curl -v http://example.com
cURL 下载(output):
$ curl --output output.html http://example.com/
$ curl -o output.html http://example.com/
cURL 重定向:(curl默认不会重定向)
$ curl --location output.html http://example.com/
$ curl -L output.html http://example.com/
使用 curl 在命令行获取网站的响应时间
curl -L -w "time_namelookup: %{time_namelookup}\ntime_connect: %{time_connect}\ntime_appconnect: %{time_appconnect}\ntime_pretransfer: %{time_pretransfer}\ntime_redirect: %{time_redirect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" https://example.com/
结果:
<!doctype html>
<html>
...
</html>
time_namelookup: 0.020519
time_connect: 0.187338
time_appconnect: 0.546461
time_pretransfer: 0.546661
time_redirect: 0.000000
time_starttransfer: 0.710620
time_total: 0.710879
time_appconnect and time_connect time tells us how much time is spent in SSL/TLS handshake. For a cleartext connection without SSL/TLS, this number is reported as zero.
Also note that time_redirect is zero in both outputs above. That is because no redirection occurs while visiting example.com.
curl post file as body
curl POST 二进制文件
strip new lines
curl --data "@/path/to/filename" http://...
keep new lines
curl --data-binary "@/path/to/filename" http://...
本文链接地址:https://const.net.cn/629.html