gpt4 book ai didi

php - Azure 上的 SimplePie 不解析 https feed

转载 作者:行者123 更新时间:2023-12-03 03:10:07 24 4
gpt4 key购买 nike

我正在使用 SimplePie 1.4.2 的编译版本(GitHub 上最后一个标记版本)聚合一些 rss/atom 提要(如果需要,可以使用下面的代码)。

它在几个基于 Linux 的 Web 主机上运行良好,但是当我将其上传到 Azure app services 时只有 http 提要可以正确显示,但 https 则不能。

为什么会发生这种情况?没有在 Web 应用程序上设置具体设置,在两种环境中都使用 PHP 5.6。通过 http 或 https 访问 azure web 应用程序没有区别。

谢谢大家!

<小时/>
<?php
date_default_timezone_set('Europe/Rome');
set_time_limit(0);
header('Content-Type: application/rss+xml; charset=UTF-8');
require_once('SimplePie.compiled.php');

[...]

echo '<?xml version="1.0" encoding="UTF-8"?>';
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title><?php echo $feedtitle; ?></title>
<atom:link href="<?php echo $feedlink; ?>" rel="self" type="application/rss+xml" />
<link><?php echo $feedhome; ?></link>
<description><?php echo $feeddesc; ?></description>
<?php
$feed = new SimplePie();
$feed->set_feed_url($feeds);
$feed->force_feed(true);
$feed->init();
$feed->handle_content_type();
foreach($feed->get_items() as $item) {
?>
<item>
<title><?php echo $item->get_title(); ?></title>
<link><?php echo $item->get_permalink(); ?></link>
<guid><?php echo $item->get_permalink(); ?></guid>
<pubDate><?php echo $item->get_date('D, d M Y H:i:s T'); ?></pubDate>
<dc:creator><?php if ($author = $item->get_author()) { echo $author->get_name()." at "; }; ?><?php if ($feed_title = $item->get_feed()->get_title()) {echo $feed_title;}?></dc:creator>
<description><![CDATA[<?php echo $item->get_content(); ?>]]></description>
</item>
<?
};
?>
</channel>
</rss>

最佳答案

它不适用于“https”网址,因为 SimplePie 利用 cURL 来发出 http 请求,而对于 https 请求,则使用 cURL 需要验证主机或对等证书。

您可以尝试以下代码片段来绕过验证。

$simplePie = new SimplePie();
$simplePie->set_curl_options(
array(
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false
)
);

这里是类似的场景 https://github.com/simplepie/simplepie/pull/407

关于php - Azure 上的 SimplePie 不解析 https feed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39637777/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com