首页 > 解决方案 > 使用 file_get_contents() 获取对本地 IP URL 的请求不起作用

问题描述

如果我直接在浏览器上调用 URL,我会得到响应,但是当我尝试使用从该 URL 获取内容file_get_contentsCURL它不返回任何内容时,会得到空页面(这里使用以本地 IP 地址开头的 url .eg : http://192.168.x.xxx/device/reader-config?action=get)。

和本地ip有关系吗?

这是我的代码,

$url = 'http://192.168.x.xxx/device/reader-config?action=get';

$username = 'username';
$password = 'password';
$context = stream_context_create(array('http' => 
        array('header' => "Authorization: Basic " . base64_encode("$username:$password"))
    ));

$rawdata = file_get_contents($url, false, $context);
print_r($rawdata);

标签: php

解决方案


推荐阅读