I have been stuck with this issue for quite a long time now. I have googled regarding this and also saw all the links associated with "chunked" in SO. So, finally decided to post this question. Let me brief the issue. I am having Java code which reads the response from a HTTPS using socket. The response is being received correctly and everything is going fine unless the transfer-encoding is "chunked". I am trying to read the chunked response from the socket as byte array and when I convert it to string the response is unreadable. I suspect that I am doing something wrong in processing the chunk data. Due to this issue I am also getting "Not in GZip format" exception when I try to decompress the response. The code which I am using to process chunks is
int chunkLength;
do {
String lengthLine = inStream.readLine();
if (lengthLine == null) {
return false;
}
chunkLength = Integer.parseInt(lengthLine.trim(), 16);
if (chunkLength > 0) {
byte[] chunk = new byte[chunkLength];
int bytesRead = inStream.read(chunk);
if (bytesRead < chunkLength) {
return false;
}
//Burn a CR/LF
inStream.readLine();
}//if chunkLength
} while (chunkLength > 0) ;
return true;
As I am new to asking question in SO I may be missing some(probably many) details which may be required for you for giving a solution. Please pardon me in such case and let me know if you need more details on this. Any help would be greatly appreciated. Cheers.