繁体   English   中英

通过PHP从外部https路径读取

[英]reading from external https path by php

我想从协议为https的外部网站上阅读一些短语。 我通过以下代码对具有http协议的网站进行了此操作:

$homepage  = file_get_contents('https://www.examlple.com/');
echo $homepage;

但不适用于https网站。 然后我用了这个:

$fp = fsockopen("https://www.example.com/", 80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, "Data sent by socket");
    $content = "";
    while (!feof($fp)) {  //This looped forever
        $content .= fread($fp, 1024);
    }
   fclose($fp);
   echo $content;
}

但我总是得到一个错误:

找不到套接字传输“ http”-在配置PHP时是否忘记启用它? (2)

实际上,情况是从分析中获取我网站的统计信息。

Fsockopen不了解“ http,https”。 请从您的域中删除http部分,然后使用SSL端口进行连接。

看例子,这应该工作:

// open ssl connection - dont add "http or https!"
$host = "ssl://" . "example.com";
$port = 443;
$fp = fsockopen($host,$port);

if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, "Data sent by socket");
    $content = "";
    while (!feof($fp)) {  //This looped forever
        $content .= fread($fp, 1024);
    }
   fclose($fp);
   echo $content;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM