-
-
Save kingreatwill/5120043e62cee8a98c3e4b9b4f4d20ce to your computer and use it in GitHub Desktop.
从HTTP Request里取得body内容得到byte数组的方法。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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