472,344 Members | 2,529 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,344 software developers and data experts.

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 3654

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

Similar topics

by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be...
by: Benjamin Bittner | last post by:
Hallo NG, ive searched a lot in some google groups, and found many threads, but nothing that helped me. Here is the scenario: I have an aspx page...
by: Shelly | last post by:
I do what most programmers do -- we steal code from stuff we have written before, or accept code from others that works, before we attempt to write...
by: mirandacascade | last post by:
Operating system: Windows XP Home Version of Python: 2.4 While looking through the tutorial on ElementSOAP at the following link: ...
by: Roland | last post by:
Hello! Firstly, sorry for my poor English... :/ Next, I want to show you my library dll - HttpClient. This library can: - get page - submit form...
by: Event Horizon | last post by:
Hi, I'm trying to add an simple upload applet to shopping cart script. My new applet form sends all needed post fields ( quantity, product,...
by: osa | last post by:
I have a problem with commons-httpclient-3.1. When i try to get some page, cookies do not come to me. There is no error or exception message. Just...
by: gsuns82 | last post by:
Hi all, I am not able to login a site using the following code, can anyone suggest me the right way? There is no any https...
by: camphor | last post by:
hi, I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.