如何使用 HTTPS 获取网站内容
使用 ssl ( HTTPs ) 的网站前: https://www.eb2a.com
1 - 我试图获取使用 file_get_contents 获取其内容,但不起作用并给出错误 ex :
<?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,但不起作用并给出空白页 例如:
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
任何人有任何想法吗?
ex of site using ssl ( HTTPs ) : https://www.eb2a.com
1 - i tried to get its content using file_get_contents, but not work and give error
ex :
<?php
$contents = file_get_contents("https://www.eb2a.com/");
echo $contents;
?>
2 - i tried to use fopen, but not work and give error
ex:
<?php
$url = 'https://www.eb2a.com/';
$contents = fopen($url, 'r');
echo "$contents";
?>
3 - i tried to use CURL, but not work and give BLANK PAGE
ex :
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
any one have any idea ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要从安全协议
https
获取内容,您需要从 php.ini 文件启用openssl
扩展并进行身份验证。To fetch the contents from secure protocal
https
, you need to haveopenssl
extenstion enabled from php.ini file and the authentication for that matter.网站重定向 301
将 url
从
更改为
或如果仍然无法正常工作或需要将其与 / 一起使用,
请查看 LINK
使用curl重定向规则
web site redirect 301
change url
from
to
or if still not working or need use it with /
loook at LINK
use curl redirect rules