Uploading a file to a CGI script

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top