Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save user20161119/c2dfe9e4738fa32ba155 to your computer and use it in GitHub Desktop.
Save user20161119/c2dfe9e4738fa32ba155 to your computer and use it in GitHub Desktop.
从HTTP Request里取得body内容得到byte数组的方法。
public byte[] parse(HttpServletRequest request) {
byte[] input = null;
try {
InputStream is = request.getInputStream();
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
while (true) {
int c = is.read();
if (c == -1) break;
byteStream.write((byte) c);
}
if (byteStream.size() > 0){
input = byteStream.toByteArray();
}
} catch (IOException e) {
Throwables.propagate(e);
}
return input;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment