简单的 PHP 和JSON

发布于 2024-12-28 10:48:13 字数 715 浏览 1 评论 0原文

我在这个脚本上遇到了麻烦。它可以在我的本地服务器和测试服务器上运行,但在我的 Rackspace 服务器上似乎无法正常运行。

<?php

$path = "http://query.yahooapis.com/v1/public/yql?q=";
$path .= urlencode("SELECT * FROM feed WHERE url='http://feeds.feedburner.com/TMSEvents'");
$path .= "&format=json";

$feed = file_get_contents($path, true);

$feed = json_decode($feed); ?>

这很简单,但我在 Rackspace 服务器上收到以下错误消息:

PHP 警告: file_get_contents(http://query.yahooapis.com/v1/public/yql?q=SELECT+%2A+FROM+feed+WHERE+url%3D%27http%3A%2F%2Ffeeds.feedburner.com%2FTMSEvents%27&格式=json) [函数.文件获取内容]: 打开流失败:HTTP 请求失败! HTTP/1.0 500 999 本页 目前不可用

任何人都知道为什么这可以在一台服务器上运行,但不能在另一台服务器上运行?谢谢!

I'm having trouble with this script. It works on my local server and test server, but doesn't seem to run correctly on my Rackspace server.

<?php

$path = "http://query.yahooapis.com/v1/public/yql?q=";
$path .= urlencode("SELECT * FROM feed WHERE url='http://feeds.feedburner.com/TMSEvents'");
$path .= "&format=json";

$feed = file_get_contents($path, true);

$feed = json_decode($feed); ?>

It is very simple, but I am getting the follow error message on the Rackspace server:

PHP Warning:
file_get_contents(http://query.yahooapis.com/v1/public/yql?q=SELECT+%2A+FROM+feed+WHERE+url%3D%27http%3A%2F%2Ffeeds.feedburner.com%2FTMSEvents%27&format=json)
[function.file-get-contents]:
failed to open stream: HTTP request failed! HTTP/1.0 500 999 This page
is currently unavailable

Anyone have any ideas why this would work on one server, but not on another? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

待"谢繁草 2025-01-04 10:48:13

看看这个: http://codular.com/curl-with-php

尝试下面的代码。经过测试,其工作正常:

<?php
$path = "http://query.yahooapis.com/v1/public/yql?q=";
$path .= urlencode("SELECT * FROM feed WHERE url='http://feeds.feedburner.com/TMSEvents'");
 $path .= "&format=json";
 // Get cURL resource
 $curl = curl_init();
 // Set some options - we are passing in a useragent too here
 curl_setopt_array($curl, array(
     CURLOPT_RETURNTRANSFER => 1,
     CURLOPT_URL => $path,
     CURLOPT_USERAGENT => 'Codular Sample cURL Request'
 ));
 // Send the request & save response to $resp
 $feed = curl_exec($curl);
 // Close request to clear up some resources
 curl_close($curl);

 $feed = json_decode($feed);
 ?>

Look on this : http://codular.com/curl-with-php

Try Below code. Its working fine with tested :

<?php
$path = "http://query.yahooapis.com/v1/public/yql?q=";
$path .= urlencode("SELECT * FROM feed WHERE url='http://feeds.feedburner.com/TMSEvents'");
 $path .= "&format=json";
 // Get cURL resource
 $curl = curl_init();
 // Set some options - we are passing in a useragent too here
 curl_setopt_array($curl, array(
     CURLOPT_RETURNTRANSFER => 1,
     CURLOPT_URL => $path,
     CURLOPT_USERAGENT => 'Codular Sample cURL Request'
 ));
 // Send the request & save response to $resp
 $feed = curl_exec($curl);
 // Close request to clear up some resources
 curl_close($curl);

 $feed = json_decode($feed);
 ?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文