hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Cox <ben_cox...@hotmail.com>
Subject RE: HTTP Trailers in HttpClient 4.0.1
Date Thu, 04 Feb 2010 23:39:45 GMT

That did it! Thanks a lot, Oleg.

Ben



----------------------------------------
> Date: Thu, 4 Feb 2010 21:02:22 +0100
> From: olegk@apache.org
> To: httpclient-users@hc.apache.org
> Subject: Re: HTTP Trailers in HttpClient 4.0.1
>
> Ben Cox wrote:
>> Ah, getting there - almost! I was making the mistake of trying to cast the InputStream
of a BufferedHttpEntity. If I instead try response.getEntity().getContent() (i.e. work with
the BasicManagedEntity that it gives me) I get an EofSensorInputStream which, I can see in
debug, wraps a ChunkedInputStream. However, the ChunkedInputStream is still invisible! Can
I somehow get access to that ChunkedInputStream?
>>
>
> You can get access to the underlying input stream from a response
> interceptor:
>
>
> -----
> HttpHost targetHost = new HttpHost("www.yahoo.com", 80, "http");
>
> DefaultHttpClient httpclient = new DefaultHttpClient();
> httpclient.addResponseInterceptor(new HttpResponseInterceptor() {
>
> public void process(
> final HttpResponse response,
> final HttpContext context) throws HttpException, IOException {
> HttpEntity entity = response.getEntity();
> if (entity != null) {
> InputStream instream = entity.getContent();
> context.setAttribute("raw-insteam", instream);
> }
> }
> });
>
> BasicHttpContext localcontext = new BasicHttpContext();
>
> HttpGet httpget = new HttpGet("/");
> HttpResponse response = httpclient.execute(targetHost, httpget,
> localcontext);
>
> System.out.println(response.getStatusLine());
>
> HttpEntity entity = response.getEntity();
> if (entity != null) {
> entity.consumeContent();
> }
>
> InputStream instream = (InputStream)
> localcontext.getAttribute("raw-insteam");
> if (instream != null && instream instanceof ChunkedInputStream) {
> Header[] footers = ((ChunkedInputStream) instream).getFooters();
> System.out.println(footers.length);
> }
> ---
>
> Hope this helps
>
> Oleg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
 		 	   		  
_________________________________________________________________
Send us your Hotmail stories and be featured in our newsletter
http://clk.atdmt.com/UKM/go/195013117/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message