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')
,它工作。
你应该已经有了一个3位数的错误代码时就表示“HTTP请求失败”。 – 2010-10-26 21:13:14
JSON.php中有什么?这看起来不像一个PHP错误。 – Lekensteyn 2010-10-26 21:15:53
'file_get_contents'后面的'var_dump($ http_response_header);'是什么? – Wrikken 2010-10-26 21:25:50