前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >记几个Curl工具使用技巧

记几个Curl工具使用技巧

作者头像
大大大黑白格子
发布2020-06-10 19:44:03
2K0
发布2020-06-10 19:44:03
举报
文章被收录于专栏:云服务笔记
1. 输出内容自动换行:
代码语言:javascript
复制
curl  -w "\n"  https://www.seekerhcl.cn/

2. 指定网卡作为出口:
代码语言:javascript
复制
curl --interface eth0 ip.sb
或
curl --int 192.168.0.10 ip.sb (此处IP是网卡对应IP地址)

3. 打印请求站点的耗时情况:
代码语言:javascript
复制
curl -o /dev/null -s -w %{http_code}::%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}"\n" https://www.seekerhcl.cn/

-o:把curl 返回的html、js 输出至回收站[ /dev/null]
-s:去掉所有状态
-w:按照后面的格式写出rt
--connect-timeout:指定tcp连接超时时间
-m:指定数据传输超时时间
http_code:状态码
time_namelookup:DNS 解析域名www.seekerhcl.cn的时间,单位为秒,如果测试的地址为IP,这里耗时即为0
time_commect:client 和 server 端建立 TCP 连接的时间
time_starttransfer:从 client 发出请求;到 web server 响应第一个字节的时间
time_total:client 发出请求;到 web server 发送回所有的相应数据的时间
speed_download:下载速度,单位 byte/s
代码语言:javascript
复制
shell> cat curl.format
time_namelookup:    %{time_namelookup}\n
time_connect:       %{time_connect}\n
time_appconnect:    %{time_appconnect}\n
time_pretransfer:   %{time_pretransfer}\n
time_redirect:      %{time_redirect}\n
time_starttransfer: %{time_starttransfer}\n
time_total:         %{time_total}\n

shell> curl -so /dev/null -w @curl.format https://www.seekerhcl.cn/
time_namelookup:    0.004029
time_connect:       0.014525
time_appconnect:    0.048664
time_pretransfer:   0.048708
time_redirect:      0.000000
time_starttransfer: 0.060849
time_total:         0.060921

4. GET、POST 提交数据
代码语言:javascript
复制
-d 等价 --data

GET:
curl https://www.seekerhcl.cn/

POST:
curl -X POST --data 'keyword=test' https://www.seekerhcl.cn/
curl -X POST --data '{"message": "one"}' https://www.seekerhcl.cn/

5. 模拟特定请求方法
代码语言:javascript
复制
GET方式,不加参数默认为GET方式
curl -Iv -X GET https://www.seekerhcl.cn/

HEAD方式, 参数 -X HEAD
curl -Iv -X HEAD https://www.seekerhcl.cn/
image.png
image.png

6. 绑定host访问站点
6.1 使用 -x 参数,通过HTTP代理方式
代码语言:javascript
复制
#弊端是仅限于访问http站点

curl -IvL http://test.seekerhcl.cn -x 123.206.14.147:80
image.png
image.png
6.2 指定HOST字段访问
代码语言:javascript
复制
#弊端是仅限于访问http站点
curl -IvL http://123.206.14.147 -H 'Host:test.seekerhcl.cn'
image.png
image.png
6.3 使用 --resolve 参数,指定解析记录来访问
代码语言:javascript
复制
# --resolve 参数格式
# --resolve <host:port:address[,address]...>
curl -IL --resolve test.seekerhcl.cn:443:123.206.14.147 https://test.seekerhcl.cn
image.png
image.png
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. 输出内容自动换行:
  • 2. 指定网卡作为出口:
  • 3. 打印请求站点的耗时情况:
  • 4. GET、POST 提交数据
  • 5. 模拟特定请求方法
  • 6. 绑定host访问站点
    • 6.1 使用 -x 参数,通过HTTP代理方式
      • 6.2 指定HOST字段访问
        • 6.3 使用 --resolve 参数,指定解析记录来访问
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档