当前位置:网站首页>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
边栏推荐
- 一加10 Pro和iPhone 13怎么选?
- VB cannot access database stocks
- 缓存穿透、缓存击穿、缓存雪崩分别是什么
- "Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
- Display opencv drawn pictures on MFC picture control control
- 【Go ~ 0到1 】 第六天 文件的读写与创建
- 什么是低代码开发?
- Capvision Rongying's prospectus in Hong Kong was "invalid": it was strictly questioned by the CSRC and required supplementary disclosure
- Learn more about the basic situation of 2022pmp examination
- 矿产行业商业供应链协同系统解决方案:构建数智化供应链平台,保障矿产资源安全供应
猜你喜欢
How to implement a delay queue?
一文掌握数仓中auto analyze的使用
Go development: how to use go singleton mode to ensure the security of high concurrency of streaming media?
被PMP考试“折磨”出来的考试心得,值得你一览
"Cannot initialize Photoshop because the temporary storage disk is full" graphic solution
周大福践行「百周年承诺」,真诚服务推动绿色环保
Implementation of super large-scale warehouse clusters in large commercial banks
【云原生】服务网格是什么“格”?
PingCode 性能测试之负载测试实践
解决el-input输入框.number数字输入问题,去掉type=“number“后面箭头问题也可以用这种方法代替
随机推荐
Developers, MySQL column finish, help you easily from installation to entry
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
ble HCI 流控机制
Vb无法访问数据库stocks
Zebras are recognized as dogs, and the reason for AI's mistakes is found by Stanford
Spark 中的 Rebalance 操作以及与Repartition操作的区别
VSCode修改缩进不成功,一保存就缩进四个空格
Hidden corners of coder Edition: five things that developers hate most
Redis 的内存淘汰策略和过期删除策略的区别
第十八届IET交直流輸電國際會議(ACDC2022)於線上成功舉辦
解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
What grade does Anxin securities belong to? Is it safe to open an account
How can programmers improve the speed of code writing?
MVC模式和三层架构
【云原生】服务网格是什么“格”?
leetcode:421. The maximum XOR value of two numbers in the array
Electronic pet dog - what is the internal structure?
新享科技发布小程序UniPro小优 满足客户移动办公场景
Two methods of MD5 encryption
[acwing] 58 weeks 4489 Longest subsequence