How to display request headers with command line curl

后端 未结 9 751
一整个雨季
一整个雨季 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 18:01

    the -v option for curl is too verbose in the error output which contains the leading *(status line) or >(request head field) or <(response head field). to get only the request head field:

    curl -v -sS www.stackoverflow.com 2>&1 >/dev/null | grep '>' | cut -c1-2 --complement
    

    to get only the request head field:

    curl -v -sS www.stackoverflow.com 2>&1 >/dev/null | grep '<' | cut -c1-2 --complement
    

    or to dump it into /tmp/test.txt file with the -D option

    curl -D /tmp/test.txt -sS www.stackoverflow.com > /dev/null
    

    in order to filter the -v output, you should direct the error output to terminal and the std output to /dev/null, the -s option is to forbid the progress metering

提交回复
热议问题