当前位置:网站首页>curl 命令妙用
curl 命令妙用
2022-07-04 15:43:00 【Wu_Candy】
curl 介绍:
curl是基于URL语法在命令行方式下工作的文件传输工具,它支持FTP,FTPS,HTTP,HTTPS,GOPHER,TELNET,DICT,FILE及LDAP等协议。curl支持HTTPS认证,并且支持HTTP的POST,PUT等方法,FTP上传,kerberos认证,HTTP上传,代理服务器,cookies,用户名/密码认证,通过http代理服务器上传文件到FTP服务器等等,功能十分强大。本文主要分享一些常用的场景:
curl 常用参数:
-I 只显示请求头信息
-d HTTP POST方式传送数据,以json格式
-o 把输出写到该文件中
-s 静默模式。不输出任何东西
-X 指定什么命令,如GET POST
-v 查看详情
-u 设置服务器的用户和密码
-H 要发送到服务端的自定义请求头
-w 完成后输出什么
-b 从文件中读取cookie信息
-F 上传文件
-# 显示进度条
No 1:curl 命令发送get请求
示例:curl -X GET http://www.xxx.com/search?data=123
No 2:curl 命令发送get请求后统计各阶段耗时
curl -o /dev/null -s -w "time_namelookup:%{time_namelookup}\ntime_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" www.xxx.com
No 3:curl 命令发送post请求
curl www.xxx.com/api/openservice/query/queryProperty -H "Content-Type:application/json" -X POST -d '{"baseCondition": {"propertyId": 1, "dateRange": {"fromDate": "2019-07-04", "toDate": "2019-07-05"}, "adults": 1,"children": 0, "rooms": 1, "channelId": 2, "sellCategories": ["PUBLIC", "NEGOTIATE"]},"extensionCondition": {"rateIds": [], "unableFlag":"False", "currency": "CNY"}, "context": {}}'
No 4:curl 命令发送post请求后统计各阶段耗时
curl -o /dev/null -s -w "time_namelookup:%{time_namelookup}\ntime_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}\n" www.xxx.com/api/openservice/query/queryProperty -H "Content-Type:application/json" -X POST -d '{"baseCondition": {"propertyId": 1, "dateRange": {"fromDate": "2019-07-04", "toDate": "2019-07-05"}, "adults": 1,"children": 0, "rooms": 1, "channelId": 2, "sellCategories": ["PUBLIC", "NEGOTIATE"]},"extensionCondition": {"rateIds": [], "unableFlag":"False", "currency": "CNY"}, "context": {}}'
No 5:curl 命令保存文件到本地
curl -o file.html http://www.xxx.com/index.html
No 6:curl 命令登录服务
curl -u name:passwd http://www.xxx.com
No 7:curl 命令构造一个请求头
curl -H "Content-Type:application/json" http://www.xxx.com
No 8:curl 命令从文件中读取cookie 信息
curl -b "cookie.txt" http://www.xxx.com
No 9:curl 命令上传文件
curl -b "cookie.txt" -F "[email protected]/temp/a.txt" http://www.xxx.com/api/upload -v
No 10:curl 命令下载文件并显示下载进度
curl -# -o abc.jpg http://www.xxx.com/abc.JPG
No 11:curl 命令清除es 里面的数据
curl -XDELETE http://10.8.102.102:9200/entity-beta-ars6_ars-reservation -uadmin:admin #清理ES
边栏推荐
- R语言plotly可视化:plotly可视化多分类变量小提琴图(multiple variable violin plot in R with plotly)
- Perfectly integrated into win11 style, Microsoft's new onedrive client is the first to see
- [Acwing] 58周赛 4490. 染色
- 开发者,MySQL专栏完更,助你轻松从安装到入门进阶
- Great Wall Securities security does not open a securities account
- 世界环境日 | 周大福用心服务推动减碳环保
- Go micro tutorial - Chapter 2 go micro V3 using gin and etcd
- VB cannot access database stocks
- 将Opencv绘制图片显示在MFC Picture Control控件上
- To sort out messy header files, I use include what you use
猜你喜欢
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
C# 更加优质的操作MongoDB数据库
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
It's too convenient. You can complete the code release and approval by nailing it!
The test experience "tortured" by the PMP test is worth your review
Chow Tai Fook fulfills the "centenary commitment" and sincerely serves to promote green environmental protection
Redis 的内存淘汰策略和过期删除策略的区别
【HCIA持续更新】网络管理与运维
如何实现一个延时队列 ?
Perfectly integrated into win11 style, Microsoft's new onedrive client is the first to see
随机推荐
一加10 Pro和iPhone 13怎么选?
The company needs to be monitored. How do ZABBIX and Prometheus choose? That's the right choice!
ble HCI 流控机制
2022PMP考试基本情况详情了解
【Go ~ 0到1 】 第六天 文件的读写与创建
egg. JS learning notes
聊聊异步编程的 7 种实现方式
【HCIA持续更新】广域网技术
Datakit -- the real unified observability agent
Linear time sequencing
Solution du système de gestion de la chaîne d'approvisionnement du parc logistique intelligent
开发者,MySQL专栏完更,助你轻松从安装到入门进阶
昆明三环闭合工程将经过这些地方,有在你家附近的吗?
Is it safe for CITIC Securities to open an account online? Is the account opening fee charged
Summary of tx.origin security issues
C# 服务器日志模块
Years of training, towards Kata 3.0! Enter the safe container experience out of the box | dragon lizard Technology
PyTorch深度学习快速入门教程
Understand ThreadLocal in one picture
新的职业已经出现,怎么能够停滞不前 ,人社部公布建筑新职业