<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[curl中为什么-d选项不能和-I连用]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Mon, 02 Dec 2013 08:52:31 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：我在写http://jackxiang.com/post/4070/ 时发现的（Post并cookie，想看http头不行），一看还真有这个问题，主要是http头部Cookie值是否真送出去了以及Post数据是否也按指定方式给Post出去，查看加密前的待发送的数据的包头信息，以查看待发送头部的cookie信息等都有用的。于是做下记录。<br/><br/>-d是用post提交表单，-I是只读取http head，提示错误Warning: You can only select one HTTP request!<br/>来自：http://bbs.csdn.net/topics/320186919<br/>实践：的确Warning: You can only select one HTTP request!<br/><br/>国外：http://stackoverflow.com/questions/286982/curl-post-data-and-headers-only<br/>Curl post data and headers only<br/>I want to get the headers only from a curl request<br/>curl -I www.google.com<br/>All grand. Now I want to do that but to pass in post data too:<br/>curl -I -d&#039;test=test&#039; www.google.com<br/>But all I get is:<br/>Warning: You can only select one HTTP request!<br/>Anyone have any idea how to do this or am I doing something stupid?<br/><br/>2 Answers<br/>The -I option tells curl to do a HEAD request while the -d&#039;test=test&#039; option tells curl to do a POST, so you&#039;re telling curl to do two different request types.<br/>curl -s -d&#039;test=test&#039; -D- -o/dev/null www.google.com <br/>or, on Windows:<br/>curl -s -d&#039;test=test&#039; -D- -onul: www.google.com <br/>That is the neatest way to do this as far as I can find. The options are:<br/>&nbsp;&nbsp;&nbsp;&nbsp;-D- Dump the header to the file listed, or stdout when - is passed, like this.<br/>&nbsp;&nbsp;&nbsp;&nbsp;-o/dev/null Send the body to the file listed. Here, we discard the body so we only see the headers.<br/>&nbsp;&nbsp;&nbsp;&nbsp;-s Silent (no progress bar)<br/><br/>-d means you are sending form data, via the POST method. -I means you are just peeking at the metadata via HEAD.<br/>I&#039;d suggest either<br/>&nbsp;&nbsp;&nbsp;&nbsp;Download to /dev/null and write the headers via the -D headerfile to the file headerfile<br/>&nbsp;&nbsp;&nbsp;&nbsp;Use -i to include the headers in the answers and skip everything from the first empty line.<br/>Old, I know, but I would suggest adding -s to clean up the output a little bit. <br/><br/>最后使用方法：<br/><textarea name="code" class="php" rows="15" cols="100">
curl -s -b &quot;sid=g1xecq; wiscookieid=142b1f7f5896ccfb; kossid=u0lfi91elib6fud84qcglfpan2; language1=zh; cachekey=fe60514b43d5e5906154002236319fc5;__gads=id=1142368c3f659057:t=1376885182:s=alni_mbrtowdkh-ojf-8kv1dvggpuplj_a;history_list=5edc7dec-4dbf-11e3-bf9b-b9856d949d58;&quot; -d&quot;action=update&amp;source=1&amp;data=XXX&quot; -D- -o/dev/null &quot;http://jackxiang.com/api/play/record &quot;
</textarea><br/>1）于是，返回服务端的头很容易看到，如下：<br/>HTTP/1.1 200 OK<br/>Server: nginx<br/>Date: Mon, 02 Dec 2013 09:57:59 GMT<br/>Content-Type: text/html;charset=utf-8<br/>Transfer-Encoding: chunked<br/>Connection: keep-alive<br/>Vary: Accept-Encoding<br/><br/>2）最后，想看发出的请求头？<br/>背景里说的：http头部Cookie值是否真送出去了以及Post数据是否也按指定方式给Post出去<br/>请求的头用 curl 是看不到的<br/>—————解决方案—————<br/>抓包软件<br/>（1）Windows下：firefox用firebug/httpfox/fiddler2/httplook/HttpAnalyzerStdV7<br/>网卡用SmartSniff <br/>（2）Linux下：用tcpdump抓包后，sz到windows上用wireshark查看http包发送的请求头：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File-&gt;ExportObjects-&gt;HTTP-&gt;找到发送的请求链接（因为还有一个回包的请求，所以要区分开），选中后，在主界面会自动定位到，展开：<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Hypertext Transfer protocol ，就能看到如下我前面发的cookie：<br/><br/>&nbsp;&nbsp;<textarea name="code" class="C#" rows="15" cols="100">
&nbsp;&nbsp;&nbsp;&nbsp;POST /api/play/record HTTP/1.1
&nbsp;&nbsp;&nbsp;&nbsp;User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
&nbsp;&nbsp;&nbsp;&nbsp;Host: my.xiyou.cntv.cn
&nbsp;&nbsp;&nbsp;&nbsp;Accept: */*
&nbsp;&nbsp;&nbsp;&nbsp;Cookie: sid=g1xecq; wiscookieid=142b1f7f5896ccfb; kossid=u0lfi91elib6fud84qcglfpan2; language1=zh; cachekey=fe60514b43d5e5906154002236319fc5;__gads=id=1142368c3f659057:t=1376885182:s=alni_mbrtowdkh-ojf-8kv1dvggpuplj_a;history_list=5edc7dec-4dbf-11e3-bf9b-b9856d949d58;
&nbsp;&nbsp;&nbsp;&nbsp;Content-Length: 260
&nbsp;&nbsp;&nbsp;&nbsp;Content-Type: application/x-www-form-urlencoded
&nbsp;&nbsp;</textarea><br/>&nbsp;&nbsp;而Post数据就在：HTML Form URL Encoded: application/x-www-form-urlencoded 下展开里面：<br/>&nbsp;&nbsp;<textarea name="code" class="php" rows="15" cols="100">
&nbsp;&nbsp;action=update&amp;source=1&amp;data=XXX
&nbsp;&nbsp;</textarea>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] curl中为什么-d选项不能和-I连用]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>