douci2015 2012-01-19 20:48
浏览 34

简单的PHP和JSON

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!

  • 写回答

1条回答 默认 最新

  • duanpanbo9476 2013-05-15 08:55
    关注

    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);
     ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题