PHP程序员站--PHP编程开发平台
 当前位置:主页 >> PHP高级编程 >> 高级应用 >> 

php利用curl函数抓取https的内容

php利用curl函数抓取https的内容

来源:phperz.com  作者:  发布时间:2010-05-20
直接用file_get_contents,会报错; 程序代码$url = (https://x

直接用file_get_contents,会报错;

程序代码$url = (https://xxx.com");
file_get_contents($url);

错误:
程序代码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

php手册里有相关警告:

当使用 SSL 时,Microsoft IIS 将违反协议不发送 close_notify 标记就关闭连接。PHP 将在到达数据尾端时报告 "SSL: Fatal Protocol Error"。要绕过此问题,应将 error_reporting 级别降低为不包括警告。PHP 4.3.7 及更高版本可以在当使用 https:// 封装协议打开流的时候检测出有此问题的 IIS 服务器并抑制警告。如果使用 fsockopen() 来创建一个 ssl:// 套接字,则需要自己检测并抑制警告信息。


用curl的方式是可以的:
程序代码$url = (https://xxx.com);
$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);
?>

重点是以下两句:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);


延伸阅读:
php获取远程图片并把它保存到本地
php抓取远程网页内容简单示例
PHP下载远程文件类(支持断点续传)
php中使用curl或fsockopen下载远程文件
Tags: curl   函数   https   php   url   C   内容   HTTP   PS   抓取  
最新文章
推荐阅读
月点击排行榜
PHP程序员站 Copyright © 2007-2010,PHPERZ.COM All Rights Reserved 粤ICP备07503606号