[function.file-get-contents]:无法打开流:HTTP请求失败

时间:2010-10-26 21:11:42

标签: php json

以下是我的代码片段:

include("JSON.php");
$json = new Services_JSON();
$value=array('jsonrpc'=>'2.0', 'method'=>'methodname', 'params'=>array('param1',"param2"),'id'=>1);
$output = $json->encode($value);
print($output);

$opts = array(
  'http'=>array(
    'method'=>"GET",
    'header'=>"Accept: application/json\r\n"."Content-type: application/json-rpc\r\n"."Content-Length:1000\r\n"  ,
 'user_agent'    => 'spider',
 'content'=>$output
  )
);

$context = stream_context_create($opts);

// Open the file using the HTTP headers set above
$file = file_get_contents('link', false, $context);

print($file);
 $value = $json->decode($file);
?>

但是我收到了这个错误:

  

[function.file-get-contents]:无法打开流:HTTP请求失败

我试过看过 php.ini 文件中的设置,看起来很好。 我尝试了file_get_contents('www.google.com')并且有效。

1 个答案:

答案 0 :(得分:0)

如果这是您要拨打的代码:

$file = file_get_contents('link', false, $context);

然后PHP试图找到“链接”作为文件。如果没有,则失败。这将是我看到的唯一合乎逻辑的问题。

顺便说一句,PHP包含json_encode / json_decode