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 21:30:51 GMT
Mark Wolter wrote:
> Hi Oleg,
>
> thanks for the hint!
> I added the interface to my project, changed the code:
> post.setRequestEntity(new FileRequestEntity(file, "UTF-8"));
>
> and it worked!
>
> is there a possibility to download the whole package "
> org.apache.commons.httpclient.contrib.benchmark" ?
>
>
>
> Mark
>
>
>   
Hi Mark (apologies for calling you Mike in my previous mail)

The code in the 'contrib' package is provided as a reference material 
only and is not distributed in a binary form. Just make a copy of this 
class and tweak it any way you see fit.

Oleg
>   
>> --- Urspr√ľngliche Nachricht ---
>> Von: Oleg Kalnichevski <olegk@apache.org>
>> An: HttpClient User Discussion <httpclient-user@jakarta.apache.org>
>> Betreff: Re: Buffered post example needed
>> Datum: Wed, 19 Apr 2006 21:17:57 +0200
>>
>> 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
>>
>>     
>
>   


---------------------------------------------------------------------
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