hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Buffered post example needed
Date Wed, 19 Apr 2006 19:17:57 GMT
Mark Wolter wrote:
> Hello,
>
> I'm searching for some example code with an buffered post to a server via
> https.
> What I was able to do is:
> Reading from a file to a String and send the String as RequestBody:
> ...
> File file = new File("c:\\temp\\ReportRequest.xml");
> 			
> int x= fis.available();
> byte b[]= new byte[x];
> fis.read(b);
> String content = new String(b);
>
> post.setRequestBody(content);
> ...
>
> But as this is a depracted method, I tried to read from the file via Stream:
> ...
> File file = new File("c:\\temp\\ReportRequest.xml");
>
> post.setRequestEntity(new InputStreamRequestEntity(new
> FileInputStream(file)));
>
> But here I'm getting the following exception:
> org.apache.commons.httpclient.ProtocolException: Unbuffered entity enclosing
> request can not be repeated.
>
>   
Mike,

Consider implementing a custom request entity that encapsulates the 
request body and making it repeatable . Something similar to this one:
http://svn.apache.org/repos/asf/jakarta/commons/proper/httpclient/trunk/src/contrib/org/apache/commons/httpclient/contrib/benchmark/FileRequestEntity.java

Hope this helps

Oleg
> When using "post.setRequestEntity(new InputStreamRequestEntity(new
> FileInputStream(file), file.length()));" the other side (the server) can not
> parse the xml correctly. 
> The error code is:
> org.xml.sax.SAXParseException: Premature end of file.
>
>
> Any suggestions?
>
>
>
>
> Thanks!
>
>
>
> Mark
>
>
>   


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


Mime
View raw message