我在我的本地 PHP 服务器中尝试了这段代码......一切正常......但是当我将此脚本上传到网络托管服务器时,身份验证不起作用。有人可以解释为什么这个脚本在网络服务器上不起作用?
"Authorization: Basic " . base64_encode("$username:$password")
脚本:
$url = 'http://xxx.xxx.xxx.xxx:9080/apex/api/query?filtername=UNITSUMM&PARM_CONTAINER='.$contrNo.'&operatorId=BIG&complexId=KSA&facilityId=DMM&yardId=RRY';
$context = stream_context_create(array(
'http' => array(
'header' => "Authorization: Basic " . base64_encode("$username:$password")
)
));
$data = @file_get_contents($url, false, $context);
$convert = explode("\n", $data);