PHP file_get_contents函数抓取https地址出错 PHP中file_get_contents函数抓取https地址出错的解决办法(两种方法)

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

PHP file_get_contents函数抓取https地址出错 PHP中file_get_contents函数抓取https地址出错的解决办法(两种方法)

  2021-03-20 我要评论
想了解PHP中file_get_contents函数抓取https地址出错的解决办法(两种方法)的相关内容吗,在本文为您仔细讲解PHP file_get_contents函数抓取https地址出错的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:file_get_contents,fiddler_抓取https,下面大家一起来学习吧。

方法一:

在php中,抓取https的网站,提示如下的错误内容:

Warning: file_get_contents() [function.file-get-contents]: failed to open stream: Invalid argument in I:Webmyphpa.php on line 16

打开php.ini文件找到 ;extension=php_openssl.dll ,去掉双引号”;” ,重启web服务器即可。

apache服务器的话,可以同时启用mod_ssl模块测试。

如果不方便修改服务器配置,可以参考使用如下的函数来解决:

代码示例:

<?php
//file_get_contents抓取https地址内容
function getCurl($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中,利用file_get_contents函数抓取url是https开头的网站网页内容时,会出现类似下面的错误警告:

Warning: file_get_contents(https://127.0.0.1/index.php) [function.file-get-contents]: failed to open stream: Invalid argument in E:\website\blog\test.php on line 25

打开php.ini找到 ;extension=php_openssl.dll ,去掉双引号”;” ,重启web服务器即可。

apache的可以同时启用mod_ssl模块测试

以上内容给大家分享了两种方法解决PHP中file_get_contents函数抓取https地址出错,希望对大家有所帮助。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们