How to display request headers with command line curl

后端 未结 9 736
一整个雨季
一整个雨季 2020-11-28 17:19

Command line curl can display response header by using -D option, but I want to see what request header it is sending. How can I do that?

9条回答
  •  清歌不尽
    2020-11-28 17:53

    I believe the command line switch you are looking for to pass to curl is -I.

    Example usage:

    $ curl -I http://heatmiser.counterhack.com/zone-5-15614E3A-CEA7-4A28-A85A-D688CC418287  
    HTTP/1.1 301 Moved Permanently
    Date: Sat, 29 Dec 2012 15:22:05 GMT
    Server: Apache
    Location: http://heatmiser.counterhack.com/zone-5-15614E3A-CEA7-4A28-A85A-D688CC418287/
    Content-Type: text/html; charset=iso-8859-1
    

    Additionally, if you encounter a response HTTP status code of 301, you might like to also pass a -L argument switch to tell curl to follow URL redirects, and, in this case, print the headers of all pages (including the URL redirects), illustrated below:

    $ curl -I -L http://heatmiser.counterhack.com/zone-5-15614E3A-CEA7-4A28-A85A-D688CC418287
    HTTP/1.1 301 Moved Permanently
    Date: Sat, 29 Dec 2012 15:22:13 GMT
    Server: Apache
    Location: http://heatmiser.counterhack.com/zone-5-15614E3A-CEA7-4A28-A85A-D688CC418287/
    Content-Type: text/html; charset=iso-8859-1
    
    HTTP/1.1 302 Found
    Date: Sat, 29 Dec 2012 15:22:13 GMT
    Server: Apache
    Set-Cookie: UID=b8c37e33defde51cf91e1e03e51657da
    Location: noaccess.php
    Content-Type: text/html
    
    HTTP/1.1 200 OK
    Date: Sat, 29 Dec 2012 15:22:13 GMT
    Server: Apache
    Content-Type: text/html
    

提交回复
热议问题