Re: how to post data to java servlet

From: Date: Sun, 19 Sep 2004 16:00:16 +0000
Subject: Re: how to post data to java servlet
References: 1 2  Groups: php.general php.general 
Request: Send a blank email to php-general+get-197199@lists.php.net to get a copy of this message
hi, And I just realize that if we use text/plain instead of application/x-www-form-urlencoded; gives error. When I use application/x-www-form-urlencoded no problem to send single data "Catalin Trifu" <catalin@isp-software.de> wrote in message news:414D5C11.9020804@isp-software.de... > 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 (#197199) next »