在 php 中使用 file_get_contents 函数抓取 https 网站内容时出错,可采用以下两种方法解决问题:
方法一:开启 openssl 扩展
打开 php.ini 文件找到 ;extension=php_openssl.dll,去掉前面的分号,保存后重启 web 服务器即可。
方法二:使用 curl 函数替代 file_get_contents
curl 抓取 https 网址内容示例:
<?php function getHttpsContent($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $result = curl_exec($ch); curl_close ($ch); return $result; ?>
本文为原创文章,版权归国外主机测评所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 微信支付提示 PHP Notice: Undefined index: HTTP_RAW_POST_DATA 错误的解决办法08/27
- ♥ DedeCMS 禁止文档设置推荐后标题加粗 DedeCMS 去掉文档推荐后的<b></b>标签08/31
- ♥ win7 下 php 运行 getenv('REMOTE_ADDR')导致 fastcgi 停止运行的解决办法10/24
- ♥ ECShop 安装过程报错:Strict Standards: Non-static method cls_image::gd_version() should not be called statically in XXX08/31
- ♥ Laravel 报 SQLSTATE[42000] Syntax error or access violation 1055 'xxx' isn't in GROUP BY.txt 错误的解决办法08/26
- ♥ 织梦 CMS 怎么在首页模板和列表页模板调用图集里的所有图片08/30