I have a client-application that uses a socket to post some data to a
server-application. The following piece of code in the client takes care of
the posting:
$sock = fsockopen("www.majstro.com", 80, $errno, $errstr, 30);
if ($sock)
{
$data = 'a=0&b=1';
fputs($sock, "POST /Web/Majstro/SD_Server.php HTTP/1.0\r\n");
fputs($sock, "Host: www.majstro.com\r\n");
fputs($sock, "Accept: */*\r\n");
fputs($sock, "Content-type: application/x-www-url-encoded\r\n");
fputs($sock, "Content-length: " . strlen($data) . "\r\n\r\n");
fputs($sock, "$data\r\n");
$headers = "";
while ($str = trim(fgets($sock, 4096)))
$headers .= "$str\n";
$body = "";
while (!feof($sock))
$body .= fgets($sock, 4096);
fclose($sock);
return $body;
}
My problem is that SD_Server.php is indeed called, but that it is unable to
extract the parameters from the HTTP-header. They are not present in $_POST,
and count($HTTP_POST_VARS) returns the value 0. On the other hand,
$_SERVER['CONTENT_LENGTH'] contains the value 7, which is exactly the string
length of "a=0&b=1". So, it seems that the data is present in the header,
but for some reason PHP just cannot parse it.
I have run out of ideas to make this work. Has anybody here a suggestion? It
might work if I use the get method instead of the post method, but I very
much like to know what is wrong with this code.
Gerard van Wilgen
--
www.majstro.com (On-line translation dictionary / Enreta tradukvortaro)
www.travlang.com/Ergane (Free translation dictionary for Windows / Senpaga
tradukvortaro por Windows)