linux-curl工具使用
环境:centos
1、超时参数解析
1 2 3 4 5 | #使用curl时,有两个超时时间: #--connect-timeout <seconds> 是连接超时时间 #-m/--max-time <seconds> 是整个过程允许的最大时间 #下面表示连接百度20秒没有连接到百度退出,整个过程40s没有返回退出 curl --connect-timeout 20 -m 40 https: //www.baidu.com |
2、静默不输出信息 -s 参数
1 2 3 4 5 6 7 | [root@minion246 wj]# curl http: //gayd.sczwfw.gov.cn:8903|grep mess #不带-s % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 62 100 62 0 0 1444 0 --:--:-- --:--:-- --:--:-- 1476 { "code" :40966, "message" : "请求的应用token位数不正确" } [root@minion246 wj]# curl -s http: //gayd.sczwfw.gov.cn:8903|grep mess #带参数-s { "code" :40966, "message" : "请求的应用token位数不正确" } |
3、获取对方的响应首部信息 -I
1 2 3 4 5 6 7 8 9 | [root@minion246 wj]# curl -I http: //gayd.sczwfw.gov.cn HTTP/1.1 200 OK Vary: Accept-Encoding Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET,HEAD,PUT,POST,DELETE Content-Type: text/plain; charset=utf-8 Content-Length: 0 Date: Wed, 23 Sep 2020 03:16:25 GMT Connection: keep-alive |
4、显示网页的全部信息
1 | curl -i "https://www.baidu.com" |
5、显示一次的http请求的通信过程
1 2 3 4 5 6 7 8 | [root@minion246 wj]# curl -v http: //gayd.sczwfw.gov.cn * About to connect() to gayd.sczwfw.gov.cn port 80 (#0) * Trying 202.61.88.250... * Connected to gayd.sczwfw.gov.cn (202.61.88.250) port 80 (#0) > GET / HTTP/1.1 > User-Agent: curl/7.29.0 > Host: gayd.sczwfw.gov.cn > Accept: */* |
6、模拟get 请求
1 2 | 当发起http请求时,curl会默认发起GET请求,也可以 "-X GET" 方式指定 curl -X GET http: //www.baidu.com |
7、模拟post提交
1 2 3 4 | 1、有body参数 curl -d "param1=value1¶m2=value2" "http://www.baidu.com" 2、有JOSN格式的body和header入参 curl -s -l -H "Content-type: application/json" -X POST -d @/wj/smrz.xml https: //gayd.sczwfw.gov.cn/e62894182afb55c9a65baab9ba9b6d18 |
做一个决定,并不难,难的是付诸行动,并且坚持到底。
分类:
linux
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)