aspose file tools*
The moose likes I/O and Streams and the fly likes How to read with HttpURLConnection when transfer-encoding: chunked ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "How to read with HttpURLConnection when transfer-encoding: chunked ?" Watch "How to read with HttpURLConnection when transfer-encoding: chunked ?" New topic
Author

How to read with HttpURLConnection when transfer-encoding: chunked ?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
My HttpURLConnection code was reading content from URLs fine until I came across pages with transfer-encoding: chunked.

Can anyone help me out with the best way to read such (textual) content?

Thanks,
James
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

The best way is the simplest way (i.e. you just read bytes from the InputStream you get from the connection).
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Thanks Paul. I have tried that, but when I get display the content, it is just a load of garbage (i.e., rather than html).

I've noticed with my HttpTracer that the response I'm trying to read includes lines that have "1000" content - presumably that describe the length of the following block and are causing a problem when trying to read the actual content. Do you know how I can handle this?

Cheers,
James

PS - As chunked transfer encoding came around in HTTP 1.1, do you know if it's possible for me to change my request GET header to HTTP/1.0 as hopefully that would mean the response wouldn't then be chunked?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to read with HttpURLConnection when transfer-encoding: chunked ?