Hi list,
I'm pretty sure I'm missing something obvious, but I just can't understand
what the root of problem is.
I try to send file from java to Tomcat6's http servlet. I need to send file
alone (and probably some parameters in request), so I don't wanna mess with
multipart libraries (commons-fileupload, httpclient). The problem is that I
can't read data from servlet's input stream - it is always empty. Here's my
code:
/////////// ON CLIENT SIDE
URL url = new URL(address);
HttpURLConnection connect = (HttpURLConnection)
url.openConnection();
connect.setRequestMethod("POST");
connect.setDoInput(true);
connect.setDoOutput(true);
connect.setAllowUserInteraction(false);
connect.setUseCaches(false);
//connect.setRequestProperty("Content-Length", "" + pack.length());
//connect.setRequestProperty("Content-Type", "text/plain");
OutputStream out = connect.getOutputStream();
FileInputStream in = new FileInputStream(pack);
IOUtils.copy(in, out);
out.flush();
out.close();
in.close();
if (connect.getResponseCode() != HttpURLConnection.HTTP_OK) {
logObj.warn("file " + pack.getPath() + " was not transfered -
response code " +
connect.getResponseCode());
return false;
}
logObj.info("file " + pack.getPath() + " transfered");
////////////// ON SERVER SIDE
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
logObj.info("Servlet started")
logObj.info(IOUtils.toString(req.getInputStream()));
}
I see "file transfered" on client side, but nothing appears in log on server
side...
Thanks in advance,
Andrey