THis can be done by copying the same http request that the remote form makes when it submits.
See the following form,
<form action="submit.php" method="post">
<input type=text name="username" />
<input type=text name="password" />
<input type=submit name="submit" value="Submit"/>
</form>
When this form is submitted there is an http request sent to submit.php
on the remote host with post method. and in the body these fields reside.
username=MYUSERNAME&password=MYPASSWORD&submit=Submit
The http request looks like
POST submit.php
Host: remotehost.com
Accpet: */*
Content-Type: x-www-form-urlencoded
Content-Length: 43
username=MYUSERNAME&password=MYPASSWORD&submit=Submit
All you have to do is mimic this request.
Curl is a popular library for this task.