function file_post_contents($url, $data, $username = null, $password = null)
{
$postdata = http_build_query($data);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n".
"Authorization: Basic " . base64_encode("$username:$password"),
'content' => $postdata
)
);
$context = stream_context_create($opts);
return file_get_contents($url, false, $context);
}
хэрэглэх заавар:
echo file_post_contents(‘http://example.com/api/json/servicegroup’,array(‘regnum’=>'ВЮ89454524’, ‘id’=>‘984’), ‘testuser’,‘testpassword’);