Squarespace RSS 提要是否被 PHP 文件拉取请求阻止?

Are Squarespace RSS feeds blocked by PHP file pull requests?

Squarespace 为所有使用其服务的博客等提供内置 RSS 提要,您可以通过在 URL 末尾附加 ?format=rss 查看任何博客的 RSS 提要对于博客。例如,http://denverdarling.com/home is a blog through Squarespace, and you can view the RSS feed for that blog through http://denverdarling.com/home?format=rss

当您在浏览器的地址栏中手动输入 RSS 提要的 URL 时,它会毫无问题地显示 RSS 内容。但是,当我尝试使用 PHP 脚本提取相同的内容时,每次都会出现错误,提示“HTTP 请求失败!HTTP/1.0 400 错误请求”

我尝试了几种不同的 PHP 函数来提取内容,但它们都会导致相同的错误。我也在几个不同的 Squarespace 博客上尝试过这个,它们又一次导致了同样的错误。我尝试过的 PHP 函数包括:file_get_contentsfopensimplexml_load_fileDOMDocument()->load() 等。所有这些都会导致“HTTP 请求失败!HTTP/1.0 400 错误请求”错误。

当我 google 主题时,我唯一看到的是你不能为受密码保护的博客提取 RSS 提要,但是自从 none 我已经尝试过的博客提取提要是受密码保护的,我不确定发生了什么。

他们可能正在阻止无头用户代理

<?php

$url = "http://denverdarling.com/home?format=rss";

$options = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
              "User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad 
  )
);

$context = stream_context_create($options);
$file = file_get_contents($url, false, $context);

var_dump($file);

这有效,他们或他们的主机正在检查请求中的 header 并过滤掉特定的东西