Authentication 使用“HTTP基本身份验证失败”;授权:基本;。base64_编码(“$user:$pass”)

Authentication 使用“HTTP基本身份验证失败”;授权:基本;。base64_编码(“$user:$pass”),authentication,php,http,Authentication,Php,Http,我在本地PHP服务器上尝试了这段代码。。。一切都很顺利。。 但是,当我将此脚本上载到web托管服务器时,身份验证不起作用。有人可以解释为什么这个脚本不能在Web服务器上工作 "Authorization: Basic " . base64_encode("$username:$password") 脚本: $url = 'http://xxx.xxx.xxx.xxx:9080/apex/api/query?filtername=UNITSUMM&PARM_CONTAINER='.$co

我在本地PHP服务器上尝试了这段代码。。。一切都很顺利。。 但是,当我将此脚本上载到web托管服务器时,身份验证不起作用。有人可以解释为什么这个脚本不能在Web服务器上工作

"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);

如果您可以发布您看到的任何错误消息,或者您可以在错误日志中找到,这将非常有用

这可能是因为您的主机提供商不允许到端口9080的传出连接,或者基于某些其他条件阻止了您的连接


如果打印出base64_encode的值($username:$password),您可能能够调试脚本-可能其中一个变量未设置为正确的值。

请在
文件获取内容之前删除
@
,并检查收到的错误。使用此格式可能值得尝试
http://user:pass@com
并检查您是否能够访问该网站。