You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Ortwin Glück <od...@odi.ch> on 2005/11/11 14:50:48 UTC

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

Hi,

You must know the parameter name F under which the PERL script expects 
the file. In a HTML form F is the name of the file input field. You have 
to give this name F as the name of the part.

Your code should probably be (but you have to check with your PERL 
script really):

File targetFile = new File(sXMLFilename);
Part[] parts1 = { new FilePart("filenm", targetFile) };

Hope that helps

Ortwin Glück

Ms Syaheeda Nanwi wrote:
> 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.
> Please help shed some light. Below are the some of the
> codes and responses:
> 
> public class UploadXMLFile {
> 
> String sXMLFilename = "c:\\Test.xml";
> 
> PostMethod filePost1 = new
> PostMethod("http://000.000.000.000/cgi-bin/upload.pl");
> 
> File targetFile = new File(sXMLFilename);
> 
> Part[] parts1 = { new StringPart("filenm",
> sXMLFilename), new FilePart(targetFile.getName(),
> targetFile) };
>       
>       filePost1.setRequestEntity (new
> MultipartRequestEntity(parts1,
> filePost1.getParams()));
>       HttpClient client = new HttpClient();
>      
> client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
>       int status = client.executeMethod(filePost1);
>       System.out.println("Status = " + status);
> 
>   if (status == HttpStatus.SC_OK) 
>   {
>    System.out.println("Upload complete, response =" +
> filePost1.getResponseBodyAsString());
>    } else 
>   {
>    System.out.println("Upload failed, response =" +
> HttpStatus.getStatusText(status));
>    }
> 
> filePost1.releaseConnection();
> 
> }
> 
> 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.
> 
> 
> 		
> __________________________________ 
> Start your day with Yahoo! - Make it your home page! 
> http://www.yahoo.com/r/hs
> 
> 
> 		
> __________________________________ 
> Yahoo! FareChase: Search multiple travel sites in one click.
> http://farechase.yahoo.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


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

Posted by Ms Syaheeda Nanwi <sy...@yahoo.com>.
Hello there,

Yes you are correct. Following your suggestion, I
replaced 
Part[] parts1 = { new StringPart("filenm",
sXMLFilename), new FilePart(targetFile.getName(),
targetFile) };

with 

Part[] parts1 = { new FilePart("filenm", targetFile)
};

and it worked. Thank you so much for the suggestion.
Have a nice day !!!

--- Ortwin Glück <od...@odi.ch> wrote:

> Hi,
> 
> You must know the parameter name F under which the
> PERL script expects 
> the file. In a HTML form F is the name of the file
> input field. You have 
> to give this name F as the name of the part.
> 
> Your code should probably be (but you have to check
> with your PERL 
> script really):
> 
> File targetFile = new File(sXMLFilename);
> Part[] parts1 = { new FilePart("filenm", targetFile)
> };
> 
> Hope that helps
> 
> Ortwin Glück
> 
> Ms Syaheeda Nanwi wrote:
> > 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.
> > Please help shed some light. Below are the some of
> the
> > codes and responses:
> > 
> > public class UploadXMLFile {
> > 
> > String sXMLFilename = "c:\\Test.xml";
> > 
> > PostMethod filePost1 = new
> >
>
PostMethod("http://000.000.000.000/cgi-bin/upload.pl");
> > 
> > File targetFile = new File(sXMLFilename);
> > 
> > Part[] parts1 = { new StringPart("filenm",
> > sXMLFilename), new FilePart(targetFile.getName(),
> > targetFile) };
> >       
> >       filePost1.setRequestEntity (new
> > MultipartRequestEntity(parts1,
> > filePost1.getParams()));
> >       HttpClient client = new HttpClient();
> >      
> >
>
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
> >       int status =
> client.executeMethod(filePost1);
> >       System.out.println("Status = " + status);
> > 
> >   if (status == HttpStatus.SC_OK) 
> >   {
> >    System.out.println("Upload complete, response
> =" +
> > filePost1.getResponseBodyAsString());
> >    } else 
> >   {
> >    System.out.println("Upload failed, response ="
> +
> > HttpStatus.getStatusText(status));
> >    }
> > 
> > filePost1.releaseConnection();
> > 
> > }
> > 
> > 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.
> > 
> > 
> > 		
> > __________________________________ 
> > Start your day with Yahoo! - Make it your home
> page! 
> > http://www.yahoo.com/r/hs
> > 
> > 
> > 		
> > __________________________________ 
> > Yahoo! FareChase: Search multiple travel sites in
> one click.
> > http://farechase.yahoo.com
> > 
> >
>
---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> httpclient-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail:
> httpclient-dev-help@jakarta.apache.org
> > 
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> httpclient-dev-help@jakarta.apache.org
> 
> 



		
__________________________________ 
Start your day with Yahoo! - Make it your home page! 
http://www.yahoo.com/r/hs

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org