Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From your code my understanding is that your approach is to open a server socket and read-in line by line.<br> What you are supposed to do here is find the header "Content-length".<br> This header shows the size of the body carried in the POST request.<br> From your question, I think that you are receiving a POST request similar to the following:</p> <pre><code>POST /path HTTP/1.1 From: myUser User-Agent: java Content-Length: 32 name1=value1&amp;name2=value2 </code></pre> <p>Note the extra new line (i.e. <code>'\n'</code>) between the HTTP headers and the actual data.<br> You should use the content length and the fact that you already know where are the data related to the HTTP headers, inside the HTTP request to parse it and extract the values of interest.<br> So that you eventually get the <code>name1=value1&amp;name2=value2</code>.<br> If you just want to do it as an exercise, go ahead.<br> It is more complex than you think and you have to look to the RFC a bit.<br> For example I do not remember it is actually a <code>'\n'</code> or a <code>'\r\n'</code> or something similar.<br> Also I do not remember if content-length will be always there (for example in the responses it can be missing and the http server may send the response in encoded chunks).<br> If you need to do it though seriously, then you should use an http server implementation.<br> There is already an http server implementation shipped in java or you can use apache's.<br> Do not try to re-invent the wheel, unless you are doing for education or fun.</p>
 

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