<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://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://jackxiang.com/post//</link>
<title><![CDATA[php抓取https的内容:PHP 的curl 请求https]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[WEB2.0]]></category>
<pubDate>Thu, 28 Jan 2010 05:05:59 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	直接用file_get_contents，会报错；<br/>程序代码$url = (https://xxx.com&quot;);<br/>file_get_contents($url);<br/>错误：<br/>程序代码Warning: file_get_contents(https://xxx.com) [function.file-get-contents]: failed to open stream: No such file or directory in D:wampwwwgrabber_clientindex.php on line 3<br/>用curl的方式是可以的：<br/>程序代码$url = (https://xxx.com);<br/><textarea name="code" class="html" rows="15" cols="100">
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
print_r($result);
?&gt;
</textarea><br/>重点是以下两句：<br/><textarea name="code" class="html" rows="15" cols="100">
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
</textarea><br/>=============================================================<br/>今天项目上线，使用php的curl模块通过https访问某个文件时出错：<br/>&nbsp;&nbsp;&nbsp;&nbsp; 这是我日志里记录的信息：<br/>2009-05-11 11:10:23 请求音频列表，错误号：60--错误描述：SSL certificate problem, verify that the CA cert is OK. Details:<br/>error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed<br/>哎，项目上线急阿，请教同事得知修改如下代码即可，添加黑体字部分就好了。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_URL, $url);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_TIMEOUT, $this-&gt;timeout);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this-&gt;timeout);<br/><textarea name="code" class="html" rows="15" cols="100">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);</textarea><br/>虽然有些简单，但是还是写下来吧，以后好作参考。<br/>// 对HTTPS网站的访问,用到了扩展库curl<br/><textarea name="code" class="html" rows="15" cols="100">&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp; $curl = curl_init();
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_HEADER, 1);
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_POST, true);
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_USERAGENT, &quot;Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)&quot;);
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_COOKIE, &quot;s_cc=true; s_sq=&#123;$oPCC-&gt;s_sq&#125;; MUID=&#123;$oPCC-&gt;MUID&#125;; MSPRequ=&#123;$strCookieMSPRequ&#125;; MSPOK=&#123;$strCookieMSPOK&#125;; CkTst=&#123;$CkTst&#125;&quot;);
&nbsp;&nbsp;&nbsp;&nbsp; //curl_setopt($curl, CURLOPT_COOKIEJAR, &quot;cookiefile&quot;); # SAME cookiefile
&nbsp;&nbsp;&nbsp;&nbsp; $base_url = &quot;https://login.live.com&quot;.$strLoginUrl;
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_URL, $base_url); # this is where you are requesting POST-method form results (working with secure connection using cookies after auth)
&nbsp;&nbsp;&nbsp;&nbsp; curl_setopt($curl, CURLOPT_POSTFIELDS, $strEntity.&quot;&amp;&quot;); # form params that&#039;ll be used to get form results
&nbsp;&nbsp;&nbsp;&nbsp; $strContent = curl_exec($curl);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//从msn中所取得的回复
&nbsp;&nbsp;&nbsp;&nbsp; curl_close ($curl);
</textarea><br/>要在PHP.ini中对curl的extension前面的分号去掉，可能还要把openssl的扩展同样打开<br/>请问如何配置curl才能支持获取https网站内容或者向https的网站提交数据 ？<br/>Linux下编译php的时候，把openssl支持一块编译进去<br/>&nbsp;&nbsp;--with-openssl[=DIR]&nbsp;&nbsp;&nbsp;&nbsp;Include OpenSSL support (requires OpenSSL &gt;= 0.9.6)<br/>&nbsp;&nbsp;--with-openssl-dir[=DIR]&nbsp;&nbsp;FTP: openssl install prefix<br/>&nbsp;&nbsp;--with-imap-ssl[=DIR]&nbsp;&nbsp;&nbsp;&nbsp;IMAP: Include SSL support. DIR is the OpenSSL install prefix<br/>&nbsp;&nbsp;--with-openssl-dir[=DIR]&nbsp;&nbsp;SNMP: openssl install prefix<br/>我一般自己编译，如果你的Linux发行版带有php5-openssl包，安装好就行了 <br/>如果是通过OpenSSL加密的https协议传输的网页，curl可以直接访问：<br/>　　curl https://that.secure.server.com<br/>window下的https 通过curl访问的配置：<br/>http://618119.com/archives/2007/10/26/16.html<br/>http://hi.baidu.com/kkwtre/blog/item/3d20fbfb9a90da204e4aea01.html<br/>http://www.enet.com.cn/article/2011/0617/A20110617874334.shtml<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>=-----------------------------------------------------------------------------------------=<br/>PHP CURL HTTPS POST:<br/><textarea name="code" class="php" rows="15" cols="100">
function vpost($url,$data)&#123; // 模拟提交数据函数
&nbsp;&nbsp;&nbsp;&nbsp;$curl = curl_init(); // 启动一个CURL会话
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER[&#039;HTTP_USER_AGENT&#039;]); // 模拟用户使用的浏览器
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
&nbsp;&nbsp;&nbsp;&nbsp;curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
&nbsp;&nbsp;&nbsp;&nbsp;$tmpInfo = curl_exec($curl); // 执行操作
&nbsp;&nbsp;&nbsp;&nbsp;if (curl_errno($curl)) &#123;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &#039;Errno&#039;.curl_error($curl);//捕抓异常
&nbsp;&nbsp;&nbsp;&nbsp;&#125;
&nbsp;&nbsp;&nbsp;&nbsp;curl_close($curl); // 关闭CURL会话
&nbsp;&nbsp;&nbsp;&nbsp;return $tmpInfo; // 返回数据
&#125;


$url = &quot;https://xxx.xxx.xxx/xxx&quot;;
$data =&quot;x=xxxxxx&quot;;
$result = vpost($url,$data);

</textarea>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] php抓取https的内容:PHP 的curl 请求https]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>