file_get_contents()
当我运行以下代码时,我正在尝试使用 PHP 函数连接到 McMyAdmin :
<?php
$url = 'http://mc.mywebsite.com/data.json?req=status';
$username = 'myuser';
$password = 'mypass';
$context = stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => sprintf("Authorization: Basic %s\r\n", base64_encode($username.':'.$password)).
"Content-type: application/x-www-form-urlencoded\r\n",
'timeout' => 3,
)
));
$data = file_get_contents($url, false, $context);
echo $data;
?>
我不断收到 401 错误。从我读过的内容来看,这应该通过身份验证。难道我做错了什么?