Re: how to post data to java servlet

From: Date: Sun, 19 Sep 2004 10:14:41 +0000
Subject: Re: how to post data to java servlet
References: 1  Groups: php.general php.general 
Request: Send a blank email to php-general+get-197169@lists.php.net to get a copy of this message
Hi,
$str = "DATA=abc&DATA=123&DATA=xxx" I believe you should encode the string with http://www.php.net/rawurlencode
but make sure u don't encode the & and = signs.
$len = strlen($str);
    $p = "POST /httpsmspp/servlet/sms HTTP/1.0\r\n";
$p.= "Host: 123.31.228.206\r\n"; $p.= "Content-type: application/x-www-form-urlencoded\r\n"; I think you the Content-Type here is wrong, since you don't encode your
string to match the content type. Perhaps text/plain might do it.
$p.= "Content-length: $len\n\n"; here there should be another line
    $p .= "\r\n";
here the \n\n should be \r\n
$p.= "$str\n"; here \n should be \r\n
$p.= "\r\n"; the above line should not exist
$server = "123.31.228.206"; $connection_timeout = 10; $fp = fsockopen ($server, 80, &$errno, &$errstr, $connection_timeout); fputs ($fp,$p);
        $recdata = "";
        while (!feof($fp))
         {
          $recdata .= fgets ($fp,128);
         }
fclose ($fp); What is the response from the server ?
Hope this helps, Catalin

« previous php.general (#197169) next »