• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Could you hold this kitten for a sec? I need to adjust this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic