无法通过file_get_contents或curl获取url,但是在浏览器中可以正常工作。
这是我的代码,
$ url =“ http://192.168.1.123/device.cgi/xxx?action=get”;
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'header' => "Authorization:Basic".base64_encode("admin:0000"),
'timeout' => 30,
'protocol_version' => 1.1,
)));
if(!$result = file_get_contents($url,FALSE, $context))
{
$error = error_get_last();
echo $error['message'];
}else{
print_r($result); die;
}
here my URL starts with my localipaddress. is there any problem to use localip with file_get_contents?
卷曲输出
卷曲错误:无法连接到192.168.1.123端口80:连接超时outbool(false)
file_get_contents输出
警告:file_get_contents(http://192.168.1.123/device.cgi/xxx?action=get):打开流失败:连接超时
请帮助我解决..