title: How can I get full Http Request via Java
body: <p>I'm trying to write a httpserver using sockets and I meet this problem.
  As everyone knows ,  a Http request is like this.</p>
  
  <pre><code>GET /index.html HTTP/1.1
  Cache-Control: max-age=0
  Host: 127.0.0.1
  Accept:xxxxx
  User-Agent: xxxx
  Connection: keep-alive
  CRLF
  This is message body！
  </code></pre>
  
  <p>The question is how can I get full Http request including message body.
  I tried to write like this.</p>
  
  <pre><code>ServerSocket serverSocket = new ServerSocket(8000);
  while (true) {
   Socket socket = serverSocket.accept();
   new Thread() {
    {
     InputStream is = socket.getInputStream();
     BufferedReader input = new BufferedReader(new InputStreamReader(is));
     String line = null;
     while ((line = input.readLine()) != null) {
      System.out.println(line);
     }
     System.out.print("finish");
    }
   }.start();
  }
  </code></pre>
  
  <p>And the console would never print "finish".Then I changed like this</p>
  
  <pre><code>ServerSocket serverSocket = new ServerSocket(8000);
  while (true) {
   Socket socket = serverSocket.accept();
   new Thread() {
    {
     InputStream is = socket.getInputStream();
     BufferedReader input = new BufferedReader(new InputStreamReader(is));
     String line = null;
     while (input.ready()) {
      line = input.readLine();
      System.out.println(line);
     }
     System.out.println("finish");
    }
   }.start();
  }
  </code></pre>
  
  <p>Things go to be better, We can see "finish"! But if I refresh the page a little bit faster.The bufferdreader will not be ready and don't get in the while{} !</p>
  
  <p><strong>I want to print all the rerquest and "finish"</strong></p>
  
  <p>Please help me.
  Thanks a lot!!</p>