curl HTTP 测试常用参数总结

curl HTTP 测试常用参数总结


  • -X:指定 HTTP 请求方法,如:

    -XPOST HTTP 请求为 POST
    -XDELETE HTTP 请求为 DELETE
    

    该参数如果不指定,如果请求中不带消息体,默认使用 GET 方法,否则使用 POST 方法,示例:

    curl -XDELETE http://127.0.0.1:8080
    
  • -d:指定消息体,如:

    curl http://127.0.0.1:8080 -d "Hello World"
    
  • -v:显示 HTTP 交互的详细过程,如:

    [root@123 ~]# curl -v  http://127.0.0.1:8080
    * About to connect() to 127.0.0.1 port 8080 (#0)
    *   Trying 127.0.0.1...
    * Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
    > GET / HTTP/1.1
    > User-Agent: curl/7.29.0
    > Host: 127.0.0.1:8080
    > Accept: */*
    > 
    < HTTP/1.1 200 OK
    < Server: openresty/1.9.3.1
    < Date: Tue, 29 Dec 2015 03:48:10 GMT
    < Content-Type: text/html
    < Content-Length: 612
    < Last-Modified: Sun, 29 Nov 2015 15:21:26 GMT
    < Connection: keep-alive
    < ETag: "565b17f6-264"
    < Accept-Ranges: bytes
    < 
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    * Connection #0 to host 127.0.0.1 left intact
    
  • -i:不加这个参数,只会显示响应中的消息体,添加这个参数,会显示响应中的响应行,响应头和消息体,如:

    [root@123 ~]# curl -i http://127.0.0.1:8080
    HTTP/1.1 200 OK
    Server: openresty/1.9.3.1
    Date: Tue, 29 Dec 2015 02:06:27 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Sun, 29 Nov 2015 15:21:26 GMT
    Connection: keep-alive
    ETag: "565b17f6-264"
    Accept-Ranges: bytes
    
    <!DOCTYPE html>
    <html>
    <head>
    <title>Welcome to nginx!</title>
    <style>
        body {
            width: 35em;
            margin: 0 auto;
            font-family: Tahoma, Verdana, Arial, sans-serif;
        }
    </style>
    </head>
    <body>
    <h1>Welcome to nginx!</h1>
    <p>If you see this page, the nginx web server is successfully installed and
    working. Further configuration is required.</p>
    
    <p>For online documentation and support please refer to
    <a href="http://nginx.org/">nginx.org</a>.<br/>
    Commercial support is available at
    <a href="http://nginx.com/">nginx.com</a>.</p>
    
    <p><em>Thank you for using nginx.</em></p>
    </body>
    </html>
    
  • -I:不显示消息体,如:

    [root@123 ~]# curl -I http://127.0.0.1:8080
    HTTP/1.1 200 OK
    Server: openresty/1.9.3.1
    Date: Tue, 29 Dec 2015 02:07:34 GMT
    Content-Type: text/html
    Content-Length: 612
    Last-Modified: Sun, 29 Nov 2015 15:21:26 GMT
    Connection: keep-alive
    ETag: "565b17f6-264"
    Accept-Ranges: bytes
    
  • -H:指定一个请求头,如:

    curl -H "Test: HelloWorld" http://127.0.0.1:8080
    

    使用该命令,在发出的请求中会多一个 HTTP 请求头:Test: HelloWorld

  • -0:使用 HTTP/1.0 发送请求,如:

    curl -O http://127.0.0.1:8080
    
  • -L:会对重定向进行处理,与 -o 参数配合使用,功能类似于 wget:

    curl -L  https://github.com/coreos/etcd/releases/download/v2.2.2/etcd-v2.2.2-linux-amd64.tar.gz -o etcd-v2.2.2-linux-amd64.tar.gz
    
  • -k:不安全的 HTTPS,客户端不用验证站点的证书,如:

    curl -k https://127.0.0.1:8443
    

    对于安全连接,还有以下参数 –ssl,–sslv2 或 -2,–sslv3 或 -3,–tlsv1 或 -l,–tlsv1.0,–tlsv1.1,–tlsv1.2

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值