I actually just did this very thing because I needed to send cookies to a page. The best method I found: snoop a lynx session.
From lynx issuing a POST, I found I needed to send the following, wrapped here in a function
NOTES:
1) The 'Referer' is a bit cheesy. I just use the base http://HOSTNAME
2) cookies are in the form "COOKIE=value; COOKIE2=value2", etc so the line would be:
Cookie: UserID=1242; Pref=123
in example
3) 'clength' is the length of your form data, thus
myname=Scott&passd=foobar
clength would be the strlen of the above.
4) After this routine, send the urlencoded data
Thus, using the below:
$request="myname=Scott&myp=foobar";
$header=BuildPostHeader("www.phpbuilder.com","/cgi-bin/notarealcgi.php","id1=haha; id2=yes",strlen($request);
DOTHESOCKOPENTHING
fputs($fp, $header . $request);
function BuildPOSTHeader($host,$file,$cookies,$clength)
{
$header="POST $file HTTP/1.0\r\n";
$header.="Host: $host\r\n";
$header.="Accept: text/html, text/plain";
$header.="Accept-Language: en\r\n";
$header.="Pragma: no-cache\r\n";
$header.="Cache-Control: no-cache\r\n";
$header.="User-Agent: Server-ReportGen1.0\r\n";
$header.="Referer: http://$host\r\n";
$header.="Cookie2: \$Version=\"1\"\r\n";
$header.="Cookie: $cookies\r\n";
$header.="Content-Type: application/x-www-form-urlencoded\r\n";
$header.="Content-length: $clength\r\n\r\n";
return $header;
}
Hope it helps!