Hi everyone, I am strgling with this problem for two weeks now. And don't have an idea what's wrong with my code.
Here is the code which SHOULD send the file using POST method to "
http://www.comefly.org/civ/uploader.php", which accepts the POST parameter "uploadfile='file'".
try {
File f = new File("D:\\Programming\\Jav
a\\ClientA
pp\\hist.t
xt");
PostMethod filePost = new PostMethod("
http://www.comefly.org/civ/uploader.php");
filePost.setParameter("Use
r-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5");
StringPart sp = new StringPart("uploadfile", "D:\\Programming\\Java\\Cl
ientApp\\h
ist.txt");
String fname = f.getName();
FilePart fp = new FilePart(fname, f);
Part[] parts = { sp, fp };
filePost.setRequestEntity(
new MultipartRequestEntity(par
ts, filePost.getParams()) );
HttpClientParams pars = new HttpClientParams();
pars.makeLenient();
pars.setParameter(pars.USE
R_AGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5");
HttpClient client = new HttpClient(pars);
int status = client.executeMethod(fileP
ost);
System.out.println("Status
: "+status);
byte[] responseBody = filePost.getResponseBody()
;
System.out.println(new String(responseBody));
} catch(IOException ioe) {
ioe.printStackTrace();
}
In other words, can somebody look through the code, and say what am I missing here, what did I do wrong, cause when sending the file through browser it is accepted, but when using my java app the connection is established, file is beeing sent (but it seems it does not gets there), and after that I receive the respopnce code = 200, that everything went OK. I am loosing my temper on this already. It looks it should work, but it doesn't.
I'd like You to run my code (supplying valid file), and check if You can succeed. I have one thought in my mind. Maybe different Java versions are crossing each others ways, cause I have all major versions installed on my winxp (1.0, 1.1.8, 1.2.2_017, 1.3.1_17, 1.4.2_10, 1.5.0_06 and 1.6.0-rc-b63).
Thanks