Brief Story: I have a Servlet which receives a request (getContentType() = audio/x-wav) that I can\'t read. I need to read this wave and save it on the server side.
Deta
Basically, the Java servlet equivalent of the following line of PHP, which is the key line in the code,
$content = file_get_contents('php://input');
is
InputStream input = request.getInputStream();
This returns basically the sole HTTP request body. You can write it to an arbitrary OutputStream
the usual Java way. For example, a new FileOutputStream("/some.wav")
.
You should only realize that the HTTP request body can be read only once and also that it would implicitly be parsed when you invoke any of the request.getParameterXxx()
methods. So if you're interested in the parameters in the request URI query string as well, then you should instead use
String queryString = request.getQueryString();
and parse it further yourself (i.e. split on &
, then split on =
, then URLDecode
the name and value).