handling HTTP POST request in java
807606Apr 6 2007 — edited Apr 6 2007I have made a simple webserver that is listening to port 80.
I am trying to figure out how to recive data sent by the post method.
The html form looks like this:
<form name="text" action="test" method="POST">
<input type="text" name="v" size="25" value="text">
<input type="submit" value="send">
</form>
I have made a loop like this just to see what is sent to the server:
while(i < 100){
indata = in.readLine();
System.out.println(indata);
i++;
}
The output looks like this:
POST /test HTTP/1.1
Host: 192.168.0.2
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; sv-SE; rv:1.8.0.11) Gecko/20070312 Firefox/1.5.0.11
Accept:text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: sv,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://192.168.0.2/test
Content-Type: application/x-www-form-urlencoded
Content-Length: 5
<--- empty line
After the empty line there's supposed to be the form data. For example V=text
But the program get stuck at the empty line and in.readLine(); is not receiving any more data. The browser is stuck on loading the page at this moment.
I know this is maybe more of a HTTP protocol than java question. But I have read alot about HTTP and didnt find any info on how to handle POST request in a server application.
So I hope that maybe someone in this forum have been working with this before in java.