Jehannes
Jehannes

Reputation: 11

Read chunked through socket

For my app I send a http-get request through a socket. Then de website sends a respone, but it is using chunked encoding. Is there a way to download the full data? Maybe I use the wrong way the download the data?

BufferedReader rsp = new BufferedReader(new InputStreamReader(Client.getInputStream()));

I have read about 'ChunkedInputStream', but I can't get it work.

Upvotes: 1

Views: 2472

Answers (3)

Sam Adamsh
Sam Adamsh

Reputation: 3391

    html.replaceAll("\r\n[0-9A-Fa-f ]+\r\n", "");

Upvotes: 0

user207421
user207421

Reputation: 311054

Use an HttpURLConnection instead of a Socket. Does it all for you.

Upvotes: 2

ratchet freak
ratchet freak

Reputation: 48226

specification of chunked encoding is here

in other words read until first "\r\n" and parse the number with radix 16 then read until you have read that many bytes and another "\r\n" (which is not part of the data) and repeat until the number equals 0

Upvotes: 1

Related Questions