<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[PHP curl使用示例]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[代码编程]]></category>
<pubDate>Wed, 08 Feb 2012 16:38:47 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	首先.php 编程不会curl就是坑爹呢/所以, 这个必须会.<br/>通过几个简单的例子说明问题,以后有需求,再研究.<br/>1.获取页面源码.<br/><div class="code"><br/>&lt;?php<br/>$url = &quot;http://www.baidu.com&quot;;<br/>$ch = curl_init();<br/>curl_setopt($ch, CURLOPT_URL, $url);<br/>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br/>$result = curl_exec($ch);<br/>curl_close($ch);<br/> <br/>var_dump($result);<br/>?&gt;<br/></div><br/>如果不设置CURLOPT_RETURNTRANSFER的话,html会自动返回输出,通过这一选项,可以把输出保存到变量中去.<br/>2.POST数据.<br/><br/><div class="code"><br/>&lt;?php<br/>$url = &quot;http://api.t.sina.com.cn/oauth/authorize?oauth_token=c61f2bd0e7c4246d12c764eba0d49450&quot;;<br/>$ch = curl_init();<br/>$param = &quot;userId=&quot;.urlencode(&quot;xxx&quot;).&quot;&amp;password=&quot;.urlencode(&quot;xxx&quot;);<br/>curl_setopt($ch, CURLOPT_URL, $url);<br/>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); <br/>curl_setopt($ch, CURLOPT_POST, 1); <br/>curl_setopt($ch, CURLOPT_POSTFIELDS, $param);<br/>$result = curl_exec($ch);<br/>curl_close($ch);<br/>print $result;<br/>?&gt;<br/></div><br/>post的数据有两者哦你,一种是:<br/><div class="code"><br/>&lt;?php<br/>$param = array(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&quot;username&quot; =&gt; &quot;xxx&quot;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&quot;password&quot;&nbsp;&nbsp;=&gt; &quot;xxx&quot;<br/>);<br/>?&gt;<br/></div><br/><br/>另一种是.<br/><div class="code"><br/>&lt;?php<br/>$param = &quot;username=xxx&amp;password=xxx&quot;;<br/>?&gt;<br/></div><br/>一般的表单用第二种,除非form中明确指出multipart/form-data,否则用第二种.两种默认的编码方式不同..<br/>3.在header中传递参数.<br/><br/><div class="code"><br/>&lt;?php<br/>$header = array(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&#039;Content-Type: application/atom+xml&#039;,<br/>&nbsp;&nbsp;&nbsp;&nbsp;$acc_req-&gt;to_header()<br/>);<br/> <br/>$ch = curl_init();<br/>curl_setopt($ch, CURLOPT_HTTPHEADER, $header);<br/>curl_setopt($ch, CURLOPT_HEADER, 1);<br/>curl_setopt($ch, CURLOPT_URL, $url);<br/>curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<br/>$result = curl_exec($ch);<br/>curl_close($ch);<br/>?&gt;<br/></div><br/>Tags - <a href="http://www.dzhope.com/tags/php/" rel="tag">php</a> , <a href="http://www.dzhope.com/tags/php_curl/" rel="tag">php_curl</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] PHP curl使用示例]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>