I am trying to send a POST via PHP using the following code:
<?php
$query = 'var1=1&var2=2&var3=3';
$request = "POST displayquery.php HTTP/1.0\r\n";
$request .= "content-type: application/x-www-form-urlencoded\r\n";
$request .= "content-length: " . strlen($query) . "\r\n";
$request .= "\r\n";
$request .= $query . "\r\n";
$fp = fsockopen('localhost', 80, $errno, $errstr, 30);
if (!$fp)
{
die();
}
if (!fputs($fp, $request))
{
die();
}
while (!feof($fp))
{
echo fgets($fp); // read response line by line, you can store it into a string or an array, then process it to filter out the HTTP response headers and keep only the body of the message
}
fclose($fp);
?>
However I recieve the following error:
HTTP/1.1 400 Bad Request Date: Sat, 31 Dec 2005 19:50:01 GMT Server: Apache/1.3.33 (Win32) PHP/5.1.1 Connection: close Content-Type: text/html; charset=iso-8859-1
Bad Request
Your browser sent a request that this server could not understand.
Invalid URI in request POST displayquery.php HTTP/1.0
Apache/1.3.33 Server at 127.0.0.1 Port 80
Any ideas?
Thanks