473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 3754

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 able to do is to update an existing record in a...
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 which loads a user control in page.onInit like...
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 something altogether new. On a previous...
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: http://effbot.org/zone/element-soap.htm I observed sample...
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 - download and upload file (you can monitor for...
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, etc... ) but the "file" post field is hardcoded in...
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 null text. What could you advise me? Code:...
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 connection. HttpClient client=new...
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 permissions to php on the upload folder (which is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.