2010-10-26 96 views
0

这里是我的代码片段:[function.file-GET-内容]:未能打开流:HTTP请求失败

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]: failed to open stream: HTTP request failed

我试图看到php.ini文件中的设置,看起来很好。 我试过file_get_contents('www.google.com'),它工作。

+1

你应该已经有了一个3位数的错误代码时就表示“HTTP请求失败”。 – 2010-10-26 21:13:14

+0

JSON.php中有什么?这看起来不像一个PHP错误。 – Lekensteyn 2010-10-26 21:15:53

+0

'file_get_contents'后面的'var_dump($ http_response_header);'是什么? – Wrikken 2010-10-26 21:25:50

回答

0

如果这是你在调用代码:

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

然后PHP是试图找到“链接”为一档。当它不,它失败。那将是我看到的唯一合乎逻辑的问题。

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

相关问题