仅使用curl从HTTP POST获取响应标头 [英] Getting only response header from HTTP POST using curl
问题描述
您可以使用HTTP HEAD仅请求标头,如 curl(1)
中的选项 -I
/ p>
One can request only the headers using HTTP HEAD, as option -I
in curl(1)
.
$ curl -I /
长时间的HTML响应体是一个痛苦的命令行,所以我想只获得标题作为我的POST请求的反馈。但是,HEAD和POST是两种不同的方法。
Lengthy HTML response bodies are a pain to get in command-line, so I'd like to get only the header as feedback for my POST requests. However, HEAD and POST are two different methods.
如何让curl只显示POST请求的响应头?
How do I get curl to display only response headers to a POST request?
推荐答案
-D, --dump-header <file>
Write the protocol headers to the specified file.
This option is handy to use when you want to store the headers
that a HTTP site sends to you. Cookies from the headers could
then be read in a second curl invocation by using the -b,
--cookie option! The -c, --cookie-jar option is however a better
way to store cookies.
。因此
curl -s -D - www.acooke.org -o /dev/null
将标头转储到stdout,并将数据发送到/ dev / null(这是一个GET,而不是POST,但你可以做有POST的东西 - 只需添加您已经用于POSTing数据的任何选项)
dumps the headers to stdout and sends the data to /dev/null (that's a GET, not a POST, but you can do the same thing with a POST - just add whatever option you're already using for POSTing data)
请注意 -
-D
,表示输出file是stdout。
note the -
after the -D
which indicates that the output "file" is stdout.
这篇关于仅使用curl从HTTP POST获取响应标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!