【问题标题】:API urll not working from file_get_contents or curl()API url 不适用于 file_get_contents 或 curl()
【发布时间】:2015-11-16 07:35:32
【问题描述】:

我正在使用 WP json api 从我的 wordpress 站点获取数据。当我从浏览器访问 url 时它工作正常。 但是当我尝试从 file_get_contents() 或使用 curl 调用它时,它返回 404 页面。

 $url = 'http://example.com/api/menus/get_menu/?menu_location=mainmenu'; // this url works from browser
 $data = file_get_contents($url);
 echo $data; // returns 404 page html

【问题讨论】:

  • 当您执行print_r($data); 时,您会得到什么?如果我没记错的话,它应该返回一个json 对象,不是吗?在这种情况下,您只需要对其进行解码并使用它。
  • 它返回 404 html,来自 wordpress
  • 你试过像here描述的那样做吗?

标签: php json wordpress


【解决方案1】:

在我的情况下,如果我想调用服务器 你需要使用 localhost 或 ip local 比如 10.200.x.x

或者你可能在 url 参数中缺少添加空格

【讨论】:

  • 请不要回答评论/问题。可以理解,您的代表太低而无法发表评论,但这并不意味着应该使用答案来使 cmets 作为替代方案。最好把它删掉。
  • 因为他得到了相同的返回 404 html,它可能和我的情况一样,。我认为我的评论增值了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
  • 1970-01-01
  • 2014-10-08
  • 1970-01-01
相关资源
最近更新 更多