Looking for a little help, I have currently written an HTTP server. It currently handles GET requests very well. However, using POST, the buffered reader seems to hang. When the request stops, the rest of the input stream is read through a buffer reader. I found a few things on Google. I tried changing the CRLF and protocol version from 1.1 to 1.0 (browsers automatically make requests like 1.1). Any ideas or help would be appreciated. Thanks
It's not safe! But it shows how to get POST data in the input stream after the initial HTTP headers.
POST, "example = true & bad = false" ..
private HashMap hashMap = new HashMap(); private StringBuffer buff = new StringBuffer(); private int c = 0; private String[] post; public PostInputStream(InputStream in) { try { //Initalizes avaliable buff if (in.available() != 0) { this.buff.appendCodePoint((this.c = in.read())); while (0 != in.available()) { //Console.output(buff.toString()); buff.appendCodePoint((this.c = in.read())); } this.post = buff.toString().split("&"); for (int i = 0; i < this.post.length; i++) { String[] n = this.post[i].split("="); if (n.length == 2) { hashMap.put(URLDecoder.decode(n[0], "UTF-8"), URLDecoder.decode(n[1], "UTF-8")); } else { Console.error("Malformed Post Request."); } } } else { Console.error("No POST Data"); } } catch (Exception e) { e.printStackTrace(); } }
, . , , HTTP, , .
BufferedReader, . , BufferedReader , ( POST ), ( ).
POST InputStream
, "\ r", "\n", "Content-Length:", ., , ., Content-Length.
, "\ r", "\n"
, "Content-Length:", .
, , .
, Content-Length.
.
. , :
karoroberts, , POST. BufferedReader.
Content-Length , char POST:
char [] buffer = new char [contentLength]; request.read();
BufferedReader. POST , : String.valueOf(buffer);
. BufferedReader.read int , , Content-Length.
Source: https://habr.com/ru/post/1720311/More articles:How to create a right-click event in all browsers - javascriptDestruction of the pointer = program failure - cOptional parameter for pointer reference? - c ++How to find out which data type to use in Python? - pythonRake suppression in catalog message - ruby ββ| fooobar.comDecrypt UIViewController property warning - objective-cProblem using .net class in ironpython - ironpythonXmlTypeAttribute does not change the type name - .netTSQL rollup -return not null - tsqlHow to write cross-browser compatible scripts? - cross-browserAll Articles