R
Rex
I need to upload a file to a CGI script on a local webserver from my
application. I'm using the following code:
FileInputStream tInputStream = new
FileInputStream(mtCurrentIcon);
ByteArrayOutputStream tBuffer = new
ByteArrayOutputStream();
int iBytes = 0;
// Read the file.
while ((iBytes = tInputStream.read())!= -1) {
tBuffer.write(iBytes);
}
URLConnection tConnection = (new
URL(SERVER_HOST+"/upload.cgi")).openConnection();
System.out.println(tConnection.getURL().getPath());
tConnection.setUseCaches(false);
tConnection.setDoOutput(true);
OutputStream tOutStream = tConnection.getOutputStream();
tOutStream.write(tBuffer.toByteArray());
tOutStream.flush();
tOutStream.close();
This does not work-neither is it able to contact the server (the
access/error logs come up empty), nor is any exception generated.
Is there a better way?
application. I'm using the following code:
FileInputStream tInputStream = new
FileInputStream(mtCurrentIcon);
ByteArrayOutputStream tBuffer = new
ByteArrayOutputStream();
int iBytes = 0;
// Read the file.
while ((iBytes = tInputStream.read())!= -1) {
tBuffer.write(iBytes);
}
URLConnection tConnection = (new
URL(SERVER_HOST+"/upload.cgi")).openConnection();
System.out.println(tConnection.getURL().getPath());
tConnection.setUseCaches(false);
tConnection.setDoOutput(true);
OutputStream tOutStream = tConnection.getOutputStream();
tOutStream.write(tBuffer.toByteArray());
tOutStream.flush();
tOutStream.close();
This does not work-neither is it able to contact the server (the
access/error logs come up empty), nor is any exception generated.
Is there a better way?