2010-10-26 95 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

相關問題