美文网首页
curl的用法指南

curl的用法指南

作者: lmmy123 | 来源:发表于2020-03-23 13:45 被阅读0次

curl是linux的常用命令之一,用来请求web服务器,即client + URL

常用API:

  • 向URL发送get请求,返回响应数据

$ curl URL

  • -A
    -A 参数指定客户端的用户代理标头,即User-Agent
  • b
    -b 参数用来向服务器发送Cookie

$ curl -b 'foo=bar' https://baidu.com

  • -d
    -d参数用于发送POST请求的数据体
  • -e
    -e参数用来设置http的请求头 Referer,表示请求的来源
  • -v
    -v 参数输出通信的整个过程,用于调试
    $ curl -v https://baidu.com
  • --trace参数也可以用于调试,还会输出原始的二进制数据
    $ curl --trace - https://baidu.com

测试dns解析时间及tcp连接时间

curl -o /dev/null -s -w ${time_namelookup}"\n"%{time_connect}"\n"%{time_appconnect}"\n"%{time_pretransfer}"\n"%{time_starttransfer}"\n"%{time_total}"\n"%{time_redirect} URL
参数解析:
-o /dev/null 表示输出结果到/dev/null
-s 表示去除状态信息
-w 表示列出后面的参数的结果

  • time_namelookup 0.004s dns解析时间,从开始到dns解析完毕的所用时间
  • time_connect 0.010s 建立到服务器的tcp所用时间
  • time_appconnect 0.068s 连接
  • time_pretransfer 0.068s 预发
  • time_starttransfer 0.075s 发出请求后,服务器返回数据的第一个字节所用时间
  • time_total 0.075
  • time_redirect 0.000

相关文章

网友评论

      本文标题:curl的用法指南

      本文链接:https://www.haomeiwen.com/subject/lccwyhtx.html