httpservletrequest accepts post

In the HTTP request is the string data:

// read string

void charReader(HttpServletRequest request) {

BufferedReader br = request.getReader();

String str, wholeStr = "";
while((str = br.readLine()) != null){
wholeStr += str;
}

System.out.println(wholeStr);

}

// binary read

void binaryReader(HttpServletRequest request) {

int len = request.getContentLength();
ServletInputStream iii = request.getInputStream();
byte[] buffer = new byte[len];
iii.read(buffer, 0, len);

}

Notice:

request.getInputStream(); request.getReader(); and request.getParameter("key"); After any one of these three functions is executed once (body data can be read normally), it will be invalid after execution.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325630747&siteId=291194637