$url = 'http://example.com/restapi/post';
$params = array(
'$p1' => $_POST['txt1'],
'$p2' => $_POST['txt2'],
);
$result = file_get_contents($url, false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query($params)
)
)));
echo $result;