未能打开流:HTTP请求失败! HTTP / 1.0 400错误的请求 [英] failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

查看:1554
本文介绍了未能打开流:HTTP请求失败! HTTP / 1.0 400错误的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎出没有在我的服务器充当了。而我得到这个错误。

It seems out of no where my server is acting up. and I'm getting this error.

    failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request

这是我的code,我已经有一年多了,现在实施,并正在一个独立的临时服务器上的证实。

This is my code that I've had implemented for over a year now, and is confirmed working on a separate staging server.

    $url = 'http://graph.facebook.com/10150624051911279/photos/all';

$response = json_decode(file_get_contents($url, true));


foreach ($response->data as $photo) {
    echo '<li><a href="' . $photo->link . '" ><img class="img" src="timthumb.php?src=' . $photo->source . '&h=175&w=175"  /></a></li>';
}

怎么可能在我的服务器上未导致此问题。我难倒。

What could possibly be failing on my server to cause this issue. I'm stumped.

推荐答案

请求应该失败,因为访问你需要获得一个访问令牌的网址。所以,Facebook的返回

The request should fail, because to access that URL you need to obtain an access token. So Facebook returns

{
   "error": {
      "message": "An access token is required to request this resource.",
      "type": "OAuthException",
      "code": 104
   }
}

沿着有400错误的请求的地位。此外,因为你打开一个URL的file_get_contents的第二个参数应该是假的(没有一点搜索包含路径,如果你知道它不存在)。

with along with a "400 Bad Request" status. Additionally since you're opening an URL the second parameter of file_get_contents should be false (there is no point to search the include path, if you know it's not there).

要仍然得到来自Facebook的响应,而忽略你能做的错误:

To still get the response from Facebook and ignore the error you can do:

$url = 'http://graph.facebook.com/10150624051911279/photos/all';
$context = stream_context_create(array(
  'http' => array(
     'ignore_errors'=>true,
     'method'=>'GET'
     // for more options check http://www.php.net/manual/en/context.http.php
   )
));
$response = json_decode(file_get_contents($url, false, $context));

这篇关于未能打开流:HTTP请求失败! HTTP / 1.0 400错误的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆