user1724416
user1724416

Reputation: 954

How to handle http POST body

I have a server that accepts post requests. The post is sent from the Apache libraries.

BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
"some code here handles status line"
While (input.ready) {
     line = input.readLine()
     if (line.length() == 0)
    break;
     System.out.println(line);
}

The problem is i never actually get the body? I only get the headers?

Thank you for any help

Upvotes: 0

Views: 139

Answers (1)

Eugene Naydenov
Eugene Naydenov

Reputation: 7295

  1. Read headers with input.readLine();
  2. Skip 2 empty lines "\r\n\r\n"
  3. Read body while line.length() != 0.

So the format could look like:

Header1\r\n
Header2\r\n
Header3\r\n\r\n
BODY
BODY
BODY...

Another option is to use com.sun.net.httpserver.HttpServer

Upvotes: 1

Related Questions