<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[刘新修]]></title> 
<link>http://pic1.liuxinxiu.com:80/index.php</link> 
<description><![CDATA[刘新修的个人博客 (Liuxinxiu'S Blog)]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[刘新修]]></copyright>
<item>
<link>http://pic1.liuxinxiu.com:80/node_url/</link>
<title><![CDATA[node.js 获取http url路径中的各个参数]]></title> 
<author>刘新修 &lt;admin@yourname.com&gt;</author>
<category><![CDATA[NodeJs平台]]></category>
<pubDate>Mon, 05 Sep 2016 00:52:40 +0000</pubDate> 
<guid>http://pic1.liuxinxiu.com:80/node_url/</guid> 
<description>
<![CDATA[ 
	<p>假设URL为：<span style="color: rgb(54, 46, 43); font-family: Arial; line-height: 26px;">http://localhost:8888/select?name=a&amp;id=5</span></p><div class="codeText"><div class="codeHead">JavaScript代码</div><ol start="1" class="dp-c"><li class="alt"><span><span>http.createServer(</span><span class="keyword">function</span><span>(request,response)&#123;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">var</span><span> pathname = url.parse(request.url).pathname;&nbsp;&nbsp;</span><span class="comment">//pathname =&gt; select&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">var</span><span> arg = url.parse(request.url).query;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//arg =&gt; name=a&amp;id=5&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(<span class="string">&quot;Request for &quot;</span><span> + arg );&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">var</span><span> str = querystring.parse(arg);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//str=&gt; &#123;name:'a',id:'5'&#125;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">var</span><span> arg1 = url.parse(request.url, </span><span class="keyword">true</span><span>).query;&nbsp;&nbsp; </span><span class="comment">//arg1 =&gt; &#123;name:'a',id:'5'&#125;&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(<span class="string">&quot;Request for &quot;</span><span> + arg1 );&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="keyword">var</span><span> name = querystring.parse(arg).name;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="comment">//name =&gt; a&nbsp;&nbsp;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(<span class="string">&quot;name = &quot;</span><span>+name);&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;console.log(<span class="string">&quot;Request for &quot;</span><span> + pathname + </span><span class="string">&quot; received.&quot;</span><span>);&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&#125;).listen(8888);&nbsp;&nbsp;&nbsp;&nbsp; </span></li></ol></div><p><span style="color: rgb(255, 0, 0); font-family: Arial; line-height: 26px;">//querystring.parse(arg)&nbsp;&nbsp; =&gt; &#123; name: 'a', id: '5' &#125;</span></p><p><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">var url = require('url');</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">var a = url.parse('http://example.com:8080/one?a=index&amp;t=article&amp;m=default');</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">console.log(a);</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);"> </span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">//输出结果：</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&#123; </span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;protocol : 'http' ,</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;auth : null ,</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;host : 'example.com:8080' ,</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;port : '8080' ,</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;hostname : 'example.com' ,</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;hash : null ,</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;search : '?a=index&amp;t=article&amp;m=default',</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;query : 'a=index&amp;t=article&amp;m=default',</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;pathname : '/one',</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;path : '/one?a=index&amp;t=article&amp;m=default',</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&nbsp;&nbsp;&nbsp;&nbsp;href : 'http://example.com:8080/one?a=index&amp;t=article&amp;m=default'</span><br style="font-family: tahoma, arial, 宋体; line-height: 25.2px;" /><span style="font-family: tahoma, arial, 宋体; line-height: 25.2px; background-color: rgb(221, 237, 251);">&#125;</span></p><br/>Tags - <a href="http://pic1.liuxinxiu.com:80/tags/node/" rel="tag">node</a> , <a href="http://pic1.liuxinxiu.com:80/tags/url/" rel="tag">url</a>
]]>
</description>
</item><item>
<link>http://pic1.liuxinxiu.com:80/node_url/#blogcomment</link>
<title><![CDATA[[评论] node.js 获取http url路径中的各个参数]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://pic1.liuxinxiu.com:80/node_url/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>