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

2025-05-29 0 85

方法一:

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模块测试。

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

代码示例:

?

1

2

3

4

5

6

7

8

9

10

11

12
<?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中,利用https://www.kuaiidc.com/tag/file_get_contents" title="file_get_contents">file_get_contents函数抓取url是https开头的网站网页内容时,会出现类似下面的错误警告:

Warning: https://www.kuaiidc.com/tag/file_get_contents" title="file_get_contents">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中https://www.kuaiidc.com/tag/file_get_contents" title="file_get_contents">file_get_contents函数抓取https地址出错,希望对大家有所帮助。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 PHP中file_get_contents函数抓取https地址出错的解决方法(两种方法) https://www.kuaiidc.com/100643.html

相关文章

发表评论
暂无评论