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?

1
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
  1.  
  2. public class UploadXMLFile { 
  3.  
  4. String sXMLFilename = "c:\\Test.xml";
  5.  
  6. PostMethod filePost1 = new PostMethod("http://000.000.000.000/cgi-bin/upload.pl");
  7.  
  8. File targetFile = new File(sXMLFilename);
  9.  
  10. Part[] parts1 = { new StringPart("filenm", sXMLFilename), new FilePart(targetFile.getName(), targetFile) };
  11.  
  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);
  17.  
  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. }
  25.  
  26. filePost1.releaseConnection();
  27.  
  28. }
  29.  
The perl program accepts "filenm" as a parameter when uploading the file. The response that I get is:

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

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

3
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...
0
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...
7
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...
1
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: ...
0
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...
2
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,...
0
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...
0
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...
5
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...
0
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...
0
better678
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...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
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...
0
jalbright99669
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...
0
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. ...
0
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...
0
hi
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...
0
Oralloy
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.