【问题标题】:how to get contents of site use HTTPS如何使用 HTTPS 获取网站内容
【发布时间】:2011-02-22 05:41:10
【问题描述】:

使用 ssl (HTTPs) 的站点前:https://www.eb2a.com

1 - 我尝试使用 file_get_contents 获取其内容,但没有成功并且报错 例如:

<?php
$contents = file_get_contents("https://www.eb2a.com/");

echo $contents;
?>

2 - 我尝试使用 fopen,但无法正常工作并报错 例如:

<?php
$url = 'https://www.eb2a.com/';
$contents = fopen($url, 'r');
echo "$contents";
?>

3 - 我尝试使用 CURL,但不起作用并给出 BLANK PAGE 例如:

function cURL($url, $ref, $header, $cookie, $p){
$ch =  curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);    
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_REFERER, $ref);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);    
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);    
if ($p) {
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
}
$result =  curl_exec($ch);
curl_close($ch);
if ($result){
    return $result;
}else{
    return '';
}
}

$file = cURL('https://www.eb2a.com/','https://www.eb2a.com/',0,0,null);
echo $file

有人知道吗??

【问题讨论】:

标签: php curl https fopen


【解决方案1】:

网站重定向 301

更改网址

来自

https://www.eb2a.com/

https://www.eb2a.com

或者如果仍然不工作或需要与 / 一起使用它

LINK

使用 curl 重定向规则

【讨论】:

    【解决方案2】:

    要从安全协议 https 中获取内容,您需要从 php.ini 文件中启用 openssl 扩展并为此进行身份验证。

    【讨论】:

      猜你喜欢
      • 2020-07-24
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 2021-01-06
      • 1970-01-01
      • 2016-07-06
      • 1970-01-01
      • 2013-10-30
      相关资源
      最近更新 更多