gzip - Jsoup and gzipped html content (Android) -
i've been trying day make thing works it's still not right yet. i've checked many posts around here , tested many different implementations i'dont know now...
here situation, have small php test file (gz.php) on server wich looks :
header("content-encoding: gzip"); print("\x1f\x8b\x08\x00\x00\x00\x00\x00"); $contents = gzcompress("is working?", 9); print($contents);
this simplest , works fine web browser.
now have android activity using jsoup has code :
url url = new url("http://myserveradress.com/gz.php"); doc = jsoup.parse(url, 1000);
which cause empty eofexception on "jsoup.parse" line.
i've read everywhere jsoup supposed parse gzipped content without having special, obviously, there's missing.
i've tried many other ways using jsoup.connect().get() or inpustream, gzipinputstream , datainpustream. did try gzdeflate() , gzencode() methods php no luck either. tried not declare header-encoding in php , try deflate content later...but clever effective...
it has "stupid" i'm missing can't tell what... has idea?
(ps : i'm using jsoup 1.7.0, latest 1 of now)
the asker indicated in comment gzcompress writing crc both incorrect , incomplete, according information here, operative code being:
// display header of gzip file // ck@medienkombinat.de! // display once echo "\x1f\x8b\x08\x00\x00\x00\x00\x00"; // figure out size , crc of original later $size = strlen($contents); $crc = crc32($contents); // compress data $contents = gzcompress($contents, 9); // can't output here, since crc messed up. // if try "echo $contents" @ point, compressed // data sent, not completely. there 4 bytes @ // end crc. 3 sent. last 1 // left in limbo. also, if "echo $contents", next // byte echo not sent client. not sure // if bug in 4.0.2 or not, best way avoid // put correct crc @ end of compressed // data. (the 1 generated gzcompress looks way wrong.) // stop opera crashing, gunzip work, , // other browsers won't keep loading indefinately. // // strip off old crc (it's there, won't displayed // way -- odd) $contents = substr($contents, 0, strlen($contents) - 4); // show compressed data echo $contents; // output crc, size of original gzip_printfourchars($crc); gzip_printfourchars($size);
jonathan hedley commented, "jsoup uses normal java gzipinputstream parse gzip, you'd hit issue java program." eofexception presumably due incomplete crc.
Comments
Post a Comment