Page 1 of 1

HTTP/1.0 POST request failing to transmit some data

Posted: Thu Jun 05, 2003 9:21 am
by Sky
The request gets a OK response, but the target page says it a (long) field was empty!

Code: Select all

<?php
function httpSimulateFormSubmit($host, $method, $path, $data) {
   $fp = @fsockopen($host, 80);
   if ($fp) {
     if ($method == 'GET') $path .= '?' . $data;
      unset($showand);
  		while (list ($k, $v) = each ($data)) {
  			if(strlen($data) != 0) $out .= "&";
  			$data2 .= $showand.urlencode($k) ."=" .urlencode($v);
  			$showand = "&";
  		}
     fputs($fp, "$method $path HTTP/1.0\n");
      echo "$method $path HTTP/1.0\n";
      
     fputs($fp, "Host: $host\n");
      echo "Host: $host\n";
      
     fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
      echo "Content-type: application/x-www-form-urlencoded\n";
      
     fputs($fp, "Content-length: " . strlen($data2) . "\n");
      echo "Content-length: " . strlen($data2) . "\n";
      
     fputs($fp, "\r\n");
      echo "\r\n";

     if ($method == 'POST') fputs($fp, $data2." \r\n");
      echo $data2;

      fputs($fp, "Connection: close\n\n");
      echo "Connection: close\n\n";

    while (!feof($fp)) $buf .= fgets($fp, 1024);
     fclose($fp);
     return $buf;
   }
   else return false;
}
?>

Posted: Thu Jun 05, 2003 7:56 pm
by Sky
Someone.. PLEASE help me... I'm at a impass on this

Posted: Fri Jun 06, 2003 1:23 pm
by Sky
*bump*

Posted: Fri Jun 06, 2003 3:33 pm
by Sky
Alright, thanks for the fountains of help. There was nothing wrong with that code. (silly me)

I mis-named a variable, thus leaving one field blank.

SOLVED