您的位置:首页 > 理论基础 > 计算机网络

php抓取https的内容的代码

2017-03-28 16:14 381 查看
直接用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

用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); 

如果请求类型是
https
,则只能用
curl
了,前者会报(至少默认情况下):

PHP Warning:
file_get_contents()
: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP?

如果你说的实现https接口指的是让别人可以用https访问你,那么就需要用
openssl
生成公私钥,然后编译apache使支持
mod_ssl
,然后再配置
httpd-ssl.conf
文件,这些让系统管理员来做吧。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: