Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting HTTP POST to work when making own Java Server
    primarykey
    data
    text
    <p>I'm looking to try and make a java server that can accept GET and POST HTTP requests. Now I've managed to get the GET method to work. But I'm not managing to get the POST method to work. My server manages to read the Request Header but doesn't seem to read the body of the message. i.e what was posted. Here is the code:</p> <pre><code>int port = 1991; ServerSocket serverSocket = new ServerSocket(port); System.err.println("The Server is on and listening on port " + port); System.out.println(" "); while (true) { Socket ClientSocketConnection = serverSocket.accept(); System.err.println("We have established a connection with a client!"); System.out.println(" "); BufferedReader ServerInput = new BufferedReader(new InputStreamReader(ClientSocketConnection.getInputStream())); DataOutputStream ServerOutput =new DataOutputStream(ClientSocketConnection.getOutputStream()); String StringInput; int iCount = 0; int CountNull = 0; while ((StringInput = ServerInput.readLine()) != null) { System.out.println(StringInput); } </code></pre> <p>Now I simply display everything that is sent through the socket. But for some reason I just dont get the requests message body and I know the Body is sent because in chrome I have this:</p> <p><img src="https://i.stack.imgur.com/zawiI.png" alt="enter image description here"></p> <p>I'm not sure how to get that "Form Data". Any help would really be appreciated!!</p> <p><strong>UPDATE:</strong></p> <p>Here is the problem further narrowed down. From sends the HTTP request fine. With an HTTP POST method we have the request header a \r\n and then the message data. The problem is when my BufferedData variable <code>ServerInput</code> reads in the \r\n (empty line) it stops reading from the <code>ServerInput</code>. Anyway to fix this? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload