• curl/wget 测试http请求的响应头信息


    1. wget –debug

    wget可以使用debug信息来查看信息头,如下:

    [root@localhost ~]# wget --debug http://192.168.1.101:8080/UFE/service/test
    DEBUG output created by Wget 1.12 on linux-gnu.
    
    --2015-03-31 19:01:03--  http://192.168.1.101:8080/UFE/service/test
    正在连接 192.168.1.101:8080... 已连接。
    Created socket 3.
    Releasing 0x000000000087cca0 (new refcount 0).
    Deleting unused 0x000000000087cca0.
    
    ---request begin---
    GET /UFE/service/test HTTP/1.0
    User-Agent: Wget/1.12 (linux-gnu)
    Accept: */ *
    Host: 192.168.1.101:8080
    Connection: Keep-Alive
    
    ---request end---
    已发出 HTTP 请求,正在等待回应...
    ---response begin---
    HTTP/1.1 200 OK
    Server: Apache-Coyote/1.1
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
    Access-Control-Max-Age: 3600
    Access-Control-Allow-Headers: x-requested-with
    Content-Type: text/plain;charset=ISO-8859-1
    Content-Length: 14
    Date: Tue, 31 Mar 2015 11:13:47 GMT
    Connection: keep-alive
    
    ---response end---
    200 OK
    Registered socket 3 for persistent reuse.
    长度:14 [text/plain]
    正在保存至: “test.1100%[======================================>] 14          --.-K/s   in 0s
    
    2015-03-31 19:01:03 (2.03 MB/s) - 已保存 “test.1” [14/14])

    2. wget -save-headers

    以使用-S、–save-headers选项,不过此时只能查看响应头部信息,注意,debug和save-headers都会输出到文件。

    3. wget --spider

    判断一个文件或者页面是否存在,可以使用一下命令:

    [root@localhost ~]# wget --spider -nv http://ip/bugfree/index.php
    2015-03-31 19:12:42 URL: http://ip/bugfree/index.php/site/login 200 OK

    4. curl -v

    可以查看url的文件头信息,如下:

    [root@localhost ~]# curl -v http://192.168.1.101:8080/UFE/service/test
    * About to connect() to 192.168.1.101 port 8080 (#0)
    *   Trying 192.168.1.101... connected
    * Connected to 192.168.1.101 (192.168.1.101) port 8080 (#0)
    > GET /UFE/service/test HTTP/1.1
    > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.8 libidn/1.18 libssh2/1.4.2
    > Host: 192.168.1.101:8080
    > Accept: */ *
    >
    < HTTP/1.1 200 OK
    < Server: Apache-Coyote/1.1
    < Access-Control-Allow-Origin: *
    < Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
    < Access-Control-Max-Age: 3600
    < Access-Control-Allow-Headers: x-requested-with
    < Content-Type: text/plain;charset=ISO-8859-1
    < Content-Length: 14
    < Date: Tue, 31 Mar 2015 11:28:11 GMT
    <
    * Connection #0 to host 192.168.1.101 left intact
    * Closing connection #0

    5. curl -I

    利用curl的-I(大写i)--head 选项仅查看响应头部信息:

    [root@localhost ~]# curl -I http://192.168.1.101:8080/UFE/service/test
    HTTP/1.1 405 Method Not Allowed
    Server: Apache-Coyote/1.1
    Access-Control-Allow-Origin: *
    Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
    Access-Control-Max-Age: 3600
    Access-Control-Allow-Headers: x-requested-with
    Allow: GET
    Content-Type: text/html;charset=utf-8
    Content-Language: en
    Content-Length: 1047
    Date: Tue, 31 Mar 2015 11:31:42 GMT

    6. 获取url的状态码

    [root@localhost ~]# curl -o /dev/null -s -w %{http_code} http://192.168.1.101:8080/UFE/service/test
    200
  • 相关阅读:
    [SoapUI] UrlEncode编码/UrlDecode解码网站
    [Token] 从index.jsp中获取Token
    [Groovy]获取当前活动的Environment,获取response中节点的name和节点的value
    [Cookie] Clear Cookie
    [Groovy] Groovy API
    [Schema] I have updated my XML Schema for my service but SoapUI still generates/validates according to the old schema.
    [SoapUI] SoapUI可以做到些什么?功能有多强大?
    [Training Video
    [JSON] Validating/Asserting JSON response with Jsonlurper
    华中农业大学第四届程序设计大赛网络同步赛 I
  • 原文地址:https://www.cnblogs.com/dorothychai/p/4381931.html
Copyright © 2020-2023  润新知