php - 使用 file_get_contents() 获取对本地 IP URL 的请求不起作用
问题描述
如果我直接在浏览器上调用 URL,我会得到响应,但是当我尝试使用从该 URL 获取内容file_get_contents
或CURL
它不返回任何内容时,会得到空页面(这里使用以本地 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);
解决方案
推荐阅读
- javascript - 如何在第二个 API 函数中访问第一个 API 函数中的变量
- phpstorm - 在之前和之后添加一个新行PhpStorm 中的标记
- python - Python - 将 .gzip 附件添加到电子邮件
- asp.net-core - 如何保证操作和日志成功?
- c# - c# asp net updatepanel 导致页面刷新
- xamarin - Xamarin.Forms 设计开始菜单
- sql - 具有深度嵌套数组循环的 SQL 查询 OpenJson
- php - 如何计算在php中具有不同值的文件的匹配数
- typescript - 从联合类型中提取字符串文字值以进行更强的类型检查
- angular - 在 Angular 8 的 Bootstrap 模式对话框中可见组件后如何运行函数?