背景:我在写http://jackxiang.com/post/4070/ 时发现的(Post并cookie,想看http头不行),一看还真有这个问题,主要是http头部Cookie值是否真送出去了以及Post数据是否也按指定方式给Post出去,查看加密前的待发送的数据的包头信息,以查看待发送头部的cookie信息等都有用的。于是做下记录。
-d是用post提交表单,-I是只读取http head,提示错误Warning: You can only select one HTTP request!
来自:http://bbs.csdn.net/topics/320186919
实践:的确Warning: You can only select one HTTP request!
国外:http://stackoverflow.com/questions/286982/curl-post-data-and-headers-only
Curl post data and headers only
I want to get the headers only from a curl request
curl -I www.google.com
All grand. Now I want to do that but to pass in post data too:
curl -I -d'test=test' www.google.com
But all I get is:
Warning: You can only select one HTTP request!
Anyone have any idea how to do this or am I doing something stupid?
2 Answers
The -I option tells curl to do a HEAD request while the -d'test=test' option tells curl to do a POST, so you're telling curl to do two different request types.
curl -s -d'test=test' -D- -o/dev/null www.google.com
or, on Windows:
curl -s -d'test=test' -D- -onul: www.google.com
That is the neatest way to do this as far as I can find. The options are:
-D- Dump the header to the file listed, or stdout when - is passed, like this.
-o/dev/null Send the body to the file listed. Here, we discard the body so we only see the headers.
-s Silent (no progress bar)
-d means you are sending form data, via the POST method. -I means you are just peeking at the metadata via HEAD.
I'd suggest either
Download to /dev/null and write the headers via the -D headerfile to the file headerfile
Use -i to include the headers in the answers and skip everything from the first empty line.
Old, I know, but I would suggest adding -s to clean up the output a little bit.
最后使用方法:
1)于是,返回服务端的头很容易看到,如下:
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 02 Dec 2013 09:57:59 GMT
Content-Type: text/html;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
2)最后,想看发出的请求头?
背景里说的:http头部Cookie值是否真送出去了以及Post数据是否也按指定方式给Post出去
请求的头用 curl 是看不到的
—————解决方案—————
抓包软件
(1)Windows下:firefox用firebug/httpfox/fiddler2/httplook/HttpAnalyzerStdV7
网卡用SmartSniff
(2)Linux下:用tcpdump抓包后,sz到windows上用wireshark查看http包发送的请求头:
File->ExportObjects->HTTP->找到发送的请求链接(因为还有一个回包的请求,所以要区分开),选中后,在主界面会自动定位到,展开:
Hypertext Transfer protocol ,就能看到如下我前面发的cookie:
而Post数据就在:HTML Form URL Encoded: application/x-www-form-urlencoded 下展开里面:
-d是用post提交表单,-I是只读取http head,提示错误Warning: You can only select one HTTP request!
来自:http://bbs.csdn.net/topics/320186919
实践:的确Warning: You can only select one HTTP request!
国外:http://stackoverflow.com/questions/286982/curl-post-data-and-headers-only
Curl post data and headers only
I want to get the headers only from a curl request
curl -I www.google.com
All grand. Now I want to do that but to pass in post data too:
curl -I -d'test=test' www.google.com
But all I get is:
Warning: You can only select one HTTP request!
Anyone have any idea how to do this or am I doing something stupid?
2 Answers
The -I option tells curl to do a HEAD request while the -d'test=test' option tells curl to do a POST, so you're telling curl to do two different request types.
curl -s -d'test=test' -D- -o/dev/null www.google.com
or, on Windows:
curl -s -d'test=test' -D- -onul: www.google.com
That is the neatest way to do this as far as I can find. The options are:
-D- Dump the header to the file listed, or stdout when - is passed, like this.
-o/dev/null Send the body to the file listed. Here, we discard the body so we only see the headers.
-s Silent (no progress bar)
-d means you are sending form data, via the POST method. -I means you are just peeking at the metadata via HEAD.
I'd suggest either
Download to /dev/null and write the headers via the -D headerfile to the file headerfile
Use -i to include the headers in the answers and skip everything from the first empty line.
Old, I know, but I would suggest adding -s to clean up the output a little bit.
最后使用方法:
1)于是,返回服务端的头很容易看到,如下:
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 02 Dec 2013 09:57:59 GMT
Content-Type: text/html;charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
2)最后,想看发出的请求头?
背景里说的:http头部Cookie值是否真送出去了以及Post数据是否也按指定方式给Post出去
请求的头用 curl 是看不到的
—————解决方案—————
抓包软件
(1)Windows下:firefox用firebug/httpfox/fiddler2/httplook/HttpAnalyzerStdV7
网卡用SmartSniff
(2)Linux下:用tcpdump抓包后,sz到windows上用wireshark查看http包发送的请求头:
File->ExportObjects->HTTP->找到发送的请求链接(因为还有一个回包的请求,所以要区分开),选中后,在主界面会自动定位到,展开:
Hypertext Transfer protocol ,就能看到如下我前面发的cookie:
而Post数据就在:HTML Form URL Encoded: application/x-www-form-urlencoded 下展开里面:
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/6849/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2013-12-3 10:43
评论列表