奇妙に聞こえるかもしれませんが、このメソッドは get/ ほとんどの POST リクエストでうまく機能しますが、時々 (最近ではよくあることですが) StringBuffer は http リクエスト (JSON) の最後に追加されたデータをキャプチャしません。どこが間違っていますか?
/**
* Parses a client request and calls the appropriate handler
* @throws Exception
*/
private void processClientRequest() throws Exception{
//Get the client request
BufferedReader clientRequest = new BufferedReader(new InputStreamReader(connectedClient.getInputStream()));
//Start response object
DataOutputStream responseToClient = new DataOutputStream(connectedClient.getOutputStream());
System.out.println(clientRequest);
String requestString = clientRequest.readLine();
String header = requestString;
//Break up request
StringTokenizer tokenizer = new StringTokenizer(header);
//Different request parts
String httpMethod = tokenizer.nextToken();
String httpQueryString = tokenizer.nextToken();
//Print client request
StringBuffer responseBuffer = new StringBuffer();
while (clientRequest.ready()) {
responseBuffer.append(requestString + " ");
System.out.println(requestString);
requestString = clientRequest.readLine();
}
//Process GET request
if (httpMethod.equals("GET")) {
processGETRequests(httpQueryString, requestString);
}else if (httpMethod.equals("POST")) {
processPOSTRequests(responseBuffer, httpQueryString);
}
}