How to display request headers with command line curl

后端 未结 9 710
一整个雨季
一整个雨季 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:11

    I had to overcome this problem myself, when debugging web applications. -v is great, but a little too verbose for my tastes. This is the (bash-only) solution I came up with:

    curl -v http://example.com/ 2> >(sed '/^*/d')
    

    This works because the output from -v is sent to stderr, not stdout. By redirecting this to a subshell, we can sed it to remove lines that start with *. Since the real output does not pass through the subshell, it is not affected. Using a subshell is a little heavy-handed, but it's the easiest way to redirect stderr to another command. (As I noted, I'm only using this for testing, so it works fine for me.)

提交回复
热议问题