Datasnap http用户验证
<?php
echo "login info:";
$url = "http://192.168.3.9:8081/datasnap/rest/TPrjMis/js/1/2";
$param = array('content'=>'I am sulin');
$_SESSION["uname"]="admin";
$_SESSION["pass"]="uv";
$userinfo=$_SESSION["uname"].":".$_SESSION["pass"];
$auth = sprintf('Authorization: Basic %s', base64_encode($userinfo)); // 加入这句
$opt = array(
'http' => array(
'method' => 'GET',
'header' => "content-type:application/x-www-form-urlencoded\r\n".$auth."\r\n", // 把$auth加入到header
'content' => http_build_query($param)
)
);
$context = stream_context_create($opt);
$ret = file_get_contents($url, false, $context);
echo $ret;
?>