<?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[[实践Ok]php socket模拟POST GET请求 fsockopen版及其Post/Get服务端用epoll进行解析的依据。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Mon, 03 Aug 2009 04:30:08 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：其实服务端用epoll进行Post及其Get解析的依据,Post先：&#92;r&#92;n&#92;r&#92;n后面的数据长度由Content-Length指定:Content-Length: 26&#92;r&#92;n<br/>&#92;r&#92;n <br/>HTML Form URL Encoded: application/x-www-form-urlencoded<br/>name=1234567&amp;button=Submit<br/>....Post数据内容段....<br/>上面是Post，讲下get更简单，其实就是&#92;r&#92;n&#92;r&#92;n结尾即算完成了（Get没有Post的数据后面为空），此时服务端可以关闭了。<br/>Connection: keep-alive&#92;r&#92;n<br/>&#92;r&#92;n<br/>———————————————————————————————————————————————————————————<br/><div class="code"><br/>function httpRequestGET($url)&#123;<br/>&nbsp;&nbsp;$url2 = parse_url($url);<br/>&nbsp;&nbsp;$url2&#91;&quot;path&quot;&#93; = ($url2&#91;&quot;path&quot;&#93; == &quot;&quot; ? &quot;/&quot; : $url2&#91;&quot;path&quot;&#93;);<br/>&nbsp;&nbsp;$url2&#91;&quot;port&quot;&#93; = ($url2&#91;&quot;port&quot;&#93; == &quot;&quot; ? 80 : $url2&#91;&quot;port&quot;&#93;);<br/>&nbsp;&nbsp;$host_ip = @gethostbyname($url2&#91;&quot;host&quot;&#93;);<br/>&nbsp;&nbsp;$fsock_timeout=20;<br/>&nbsp;&nbsp;if(($fsock = fsockopen($host_ip, 80, $errno, $errstr, $fsock_timeout)) &lt; 0)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;$request =&nbsp;&nbsp;$url2&#91;&quot;path&quot;&#93; . ($url2&#91;&quot;query&quot;&#93; != &quot;&quot; ? &quot;?&quot; . $url2&#91;&quot;query&quot;&#93; : &quot;&quot;) . ($url2&#91;&quot;fragment&quot;&#93; != &quot;&quot; ? &quot;#&quot; . $url2&#91;&quot;fragment&quot;&#93; : &quot;&quot;);<br/>&nbsp;&nbsp;$in&nbsp;&nbsp;= &quot;GET &quot; . $request . &quot; HTTP/1.0&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;Accept: */*&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;User-Agent: Payb-Agent&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;Host: &quot; . $url2&#91;&quot;host&quot;&#93; . &quot;&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;Connection: Close&#92;r&#92;n&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;if(!@fwrite($fsock, $in, strlen($in)))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;fclose($fsock);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;unset($in);<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;$out = &quot;&quot;;<br/>&nbsp;&nbsp;while($buff = @fgets($fsock, 2048))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$out .= $buff;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;fclose($fsock);<br/>&nbsp;&nbsp;$pos = strpos($out, &quot;&#92;r&#92;n&#92;r&#92;n&quot;);<br/>&nbsp;&nbsp;$head = substr($out, 0, $pos);&nbsp;&nbsp;&nbsp;&nbsp;//http head<br/>&nbsp;&nbsp;$status = substr($head, 0, strpos($head, &quot;&#92;r&#92;n&quot;));&nbsp;&nbsp;&nbsp;&nbsp;//http status line<br/>&nbsp;&nbsp;$body = substr($out, $pos + 4, strlen($out) - ($pos + 4));//page body<br/>&nbsp;&nbsp;if(preg_match(&quot;/^HTTP&#92;/&#92;d&#92;.&#92;d&#92;s(&#91;&#92;d&#93;+)&#92;s.*$/&quot;, $status, $matches))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if(intval($matches&#91;1&#93;) / 100 == 2)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $body;&nbsp;&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;else&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&#125;else&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/>function httpRequestPOST($url,$post_data)&#123;<br/>&nbsp;&nbsp;$url2 = parse_url($url);<br/>&nbsp;&nbsp;$url2&#91;&quot;path&quot;&#93; = ($url2&#91;&quot;path&quot;&#93; == &quot;&quot; ? &quot;/&quot; : $url2&#91;&quot;path&quot;&#93;);<br/>&nbsp;&nbsp;$url2&#91;&quot;port&quot;&#93; = ($url2&#91;&quot;port&quot;&#93; == &quot;&quot; ? 80 : $url2&#91;&quot;port&quot;&#93;);<br/>&nbsp;&nbsp;$host_ip = @gethostbyname($url2&#91;&quot;host&quot;&#93;);<br/>&nbsp;&nbsp;$fsock_timeout=20;//秒<br/>&nbsp;&nbsp;if(($fsock = fsockopen($host_ip, 80, $errno, $errstr, $fsock_timeout)) &lt; 0)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;$request =&nbsp;&nbsp;$url2&#91;&quot;path&quot;&#93; . ($url2&#91;&quot;query&quot;&#93; != &quot;&quot; ? &quot;?&quot; . $url2&#91;&quot;query&quot;&#93; : &quot;&quot;) . ($url2&#91;&quot;fragment&quot;&#93; != &quot;&quot; ? &quot;#&quot; . $url2&#91;&quot;fragment&quot;&#93; : &quot;&quot;);<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;$needChar = false;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;foreach($post_data as $key =&gt; $val)&nbsp;&nbsp;&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;$post_data2 .= ($needChar ? &quot;&amp;&quot; : &quot;&quot;) . urlencode($key) . &quot;=&quot; . urlencode($val);<br/>&nbsp;&nbsp;&nbsp;&nbsp;$needChar = true;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;$in&nbsp;&nbsp;= &quot;POST &quot; . $request . &quot; HTTP/1.0&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;Accept: */*&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;Host: &quot; . $url2&#91;&quot;host&quot;&#93; . &quot;&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;User-Agent: Lowell-Agent&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;Content-type: application/x-www-form-urlencoded&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;Content-Length: &quot; . strlen($post_data2) . &quot;&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= &quot;Connection: Close&#92;r&#92;n&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;$in .= $post_data2 . &quot;&#92;r&#92;n&#92;r&#92;n&quot;;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;unset($post_data2);<br/>&nbsp;&nbsp;if(!@fwrite($fsock, $in, strlen($in)))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;fclose($fsock);<br/>&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;unset($in);<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;$out = &quot;&quot;;<br/>&nbsp;&nbsp;while($buff = fgets($fsock, 2048))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;$out .= $buff;<br/>&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;<br/>&nbsp;&nbsp;fclose($fsock);<br/>&nbsp;&nbsp;$pos = strpos($out, &quot;&#92;r&#92;n&#92;r&#92;n&quot;);<br/>&nbsp;&nbsp;$head = substr($out, 0, $pos);&nbsp;&nbsp;&nbsp;&nbsp;//http head<br/>&nbsp;&nbsp;$status = substr($head, 0, strpos($head, &quot;&#92;r&#92;n&quot;));&nbsp;&nbsp;&nbsp;&nbsp;//http status line<br/>&nbsp;&nbsp;$body = substr($out, $pos + 4, strlen($out) - ($pos + 4));//page body<br/>&nbsp;&nbsp;if(preg_match(&quot;/^HTTP&#92;/&#92;d&#92;.&#92;d&#92;s(&#91;&#92;d&#93;+)&#92;s.*$/&quot;, $status, $matches))&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;if(intval($matches&#91;1&#93;) / 100 == 2)&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return $body;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;else&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#125;<br/>&nbsp;&nbsp;&#125;else&#123;<br/>&nbsp;&nbsp;&nbsp;&nbsp;return false;<br/>&nbsp;&nbsp;&#125;<br/>&#125;<br/><br/></div><br/>函数调用：<br/><div class="code"><br/>$post_data = array(&quot;name&quot;=&gt;&quot;xd&quot;,&quot;sex&quot;=&gt;&quot;man&quot;);<br/>httpRequestPOST(&quot;http://localhost/post.php&quot;,$post_data);<br/></div><br/>socket写的顺序：<br/><div class="code"><br/>POST /post.php HTTP/1.0<br/>Accept: */*<br/>Host: localhost<br/>User-Agent: Lowell-Agent<br/>Content-type: application/x-www-form-urlencoded<br/>Content-Length: 15<br/>Connection: Close<br/>name=xd&amp;sex=man<br/></div><br/><br/>普通POST的结果演示：<br/><div class="code">POST/?username=111&amp;password=222HTTP/1.1<br/>Host:127.0.0.1:8000<br/>User-Agent:Mozilla/5.0(Windows;U;WindowsNT5.2;zh-CN;rv:1.9.0.1)Gecko/2008070208Firefox/3.0.1<br/>Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<br/>Accept-Language:zh-cn,zh;q=0.5<br/>Accept-Encoding:gzip,deflate<br/>Accept-Charset:gb2312,utf-8;q=0.7,*;q=0.7<br/>Keep-Alive:300<br/>Connection:keep-alive<br/>Referer:http://127.0.0.1:8000/?username=111&amp;password=222<br/>Content-Type:application/x-www-form-urlencoded<br/>Content-Length:25<br/>username=111&amp;password=222</div><br/><br/><br/><br/>GET的运行结果演示：<br/><br/><div class="code">GET/?username=111&amp;password=222HTTP/1.1<br/>Host:127.0.0.1:8000<br/>User-Agent:Mozilla/5.0(Windows;U;WindowsNT5.2;zh-CN;rv:1.9.0.1)Gecko/2008070208Firefox/3.0.1<br/>Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<br/>Accept-Language:zh-cn,zh;q=0.5<br/>Accept-Encoding:gzip,deflate<br/>Accept-Charset:gb2312,utf-8;q=0.7,*;q=0.7<br/>Keep-Alive:300<br/>Connection:keep-alive<br/>Referer:http://127.0.0.1:8000/?username=1&amp;password=2</div><br/><br/>POST文件上传的结果演示：<br/><br/><div class="code">POST/?username=111&amp;password=222HTTP/1.1<br/>Host:127.0.0.1:8000<br/>User-Agent:Mozilla/5.0(Windows;U;WindowsNT5.2;zh-CN;rv:1.9.0.1)Gecko/2008070208Firefox/3.0.1<br/>Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8<br/>Accept-Language:zh-cn,zh;q=0.5<br/>Accept-Encoding:gzip,deflate<br/>Accept-Charset:gb2312,utf-8;q=0.7,*;q=0.7<br/>Keep-Alive:300<br/>Connection:keep-alive<br/>Referer:http://127.0.0.1:8000/?username=111&amp;password=222<br/>Content-Type:multipart/form-data;boundary=---------------------------23757983230932<br/>Content-Length:1704<br/>-----------------------------23757983230932<br/>Content-Disposition:form-data;name=&quot;phototitle&quot;<br/>12<br/>-----------------------------23757983230932<br/>Content-Disposition:form-data;name=&quot;photo&quot;;filename=&quot;技术考核题.txt&quot;<br/>Content-Type:text/plain<br/>技术考核<br/>本次是个编程题，题目选Java/语言进行回答。<br/>问题描述：<br/>假设你的爱好是集邮。目前总共有N种不同的邮票，编号为从0到N-1.每种邮票的价钱被定义在数组int&#91;&#93;prices中(序号从0开始，数组的第i个元素表示第i种邮票的价格)。<br/>你的目标是收集尽可能多种的邮票。你当前拥有的邮票存储在int&#91;&#93;have这个数组中。初始时，你没有钱，但是你可以卖掉已有邮票来买不同的邮票。返回你能收集到的不同种邮票的最大数量。<br/>定义：<br/>class:PostmarksCollection<br/>method:numberOfDistinctPostmarks<br/>Parameters:int&#91;&#93;,int&#91;&#93;<br/>Returns:int<br/>Methodsignature:publicintnumberOfDistinctPostmarks(int&#91;&#93;prices,int&#91;&#93;have)<br/>//为了进行测试，必须保证是public<br/>约束：<br/>1）N从1到50<br/>2）prices中的元素数量刚好是N个元素<br/>3）prices中的元素的值，从1到1,000,000<br/>4）have中的元素数量是0个到N个<br/>5）have中的每个元素是不同的<br/>6）have中的每个元素的值是从0到N-1.<br/>例如：<br/>1）<br/>&#123;13,10,14,20&#125;<br/>&#123;3,0,2,1&#125;<br/>Returns:4<br/>你已经拥有所有种类的邮票。<br/>2）<br/>&#123;7,5,9,7&#125;<br/>&#123;&#125;<br/>Returns:0<br/>你开始没有任何邮票，所以你也不能组任何事情。<br/>3）<br/>&#123;4,13,9,1,5&#125;<br/>&#123;1,3,2&#125;<br/>Returns:4<br/>卖掉邮票2，买入邮票0和4,(邮票2的价钱是9，邮票0的价钱是4，邮票4的价钱是5，卖掉2刚好买入0和4）<br/>4）<br/>&#123;16,32,13,2,17,10,8,8,20,17&#125;<br/>&#123;7,0,4,1,6,8&#125;<br/>Returns:8<br/>--------------------------------------------------------------------------------<br/>使用Java请在此处答题（请使用JDK5.0编译，编译不能通过者不计算分数）<br/>-----------------------------23757983230932--</div>
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践Ok]php socket模拟POST GET请求 fsockopen版及其Post/Get服务端用epoll进行解析的依据。]]></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>