469,906 Members | 2,160 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,906 developers. It's quick & easy.

Httpclient upload: Success status but XML file is 0 KB?

Hi, I am trying to upload XML files via HTTP to an HTTP server from java client instead of browser. On the HTTP server side, there is a Perl script that will be receiving the incoming file and files it into the designated folders in the server.When I run the Java client, I get the response Status = 200 and also uploaded replies from the Perl script but when I checked in the folder, the XML file is 0 KB. I am not sure what went wrong. Spending a few days now looking into it but no luck.Sigh !!! Please help shed some light. Below are the some of the codes and responses:

Expand|Select|Wrap|Line Numbers
  2. public class UploadXMLFile { 
  4. String sXMLFilename = "c:\\Test.xml";
  6. PostMethod filePost1 = new PostMethod("");
  8. File targetFile = new File(sXMLFilename);
  10. Part[] parts1 = { new StringPart("filenm", sXMLFilename), new FilePart(targetFile.getName(), targetFile) };
  12. filePost1.setRequestEntity (new MultipartRequestEntity(parts1, filePost1.getParams()));
  13. HttpClient client = new HttpClient();
  14. client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
  15. int status = client.executeMethod(filePost1);
  16. System.out.println("Status = " + status);
  18. if (status == HttpStatus.SC_OK) 
  19. {
  20. System.out.println("Upload complete, response =" + filePost1.getResponseBodyAsString());
  21. } else 
  22. {
  23. System.out.println("Upload failed, response =" + HttpStatus.getStatusText(status));
  24. }
  26. filePost1.releaseConnection();
  28. }
The perl program accepts "filenm" as a parameter when uploading the file. The response that I get is:

Status = 200
Upload complete, response =
<P>Thank you. We have received your file! Test.xml </P>

Hope someone can help me on this. Thanks in advance.
Nov 11 '05 #1
0 3547

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by dave | last post: by
reply views Thread by Benjamin Bittner | last post: by
7 posts views Thread by Shelly | last post: by
1 post views Thread by mirandacascade | last post: by
2 posts views Thread by Event Horizon | last post: by
5 posts views Thread by camphor | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.