从PHP的file_get_contents响应获取bool(false)错误

时间:2018-07-27 23:09:27

标签: php error-handling file-get-contents

我不确定自己在做什么错。我使用与PUT相同的脚本,并且可以正常工作,但是当我使用GET时,会得到bool(false)

即使我直接在浏览器中访问该网址,我也会得到正确的响应

http://192.168.1.11:189/infinias/ia/Doors?DoorIds=2&username=username&password=password

PHP

$url = 'http://192.168.1.11:189/infinias/ia/Doors';
$data = array('DoorIds' => '2', 'username' => 'username', 'password' => 'password');

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'GET',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);

0 个答案:

没有答案