简体   繁体   中英

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

  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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM