Java URLConnection response is encoded -
import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstreamreader; import java.net.malformedurlexception; import java.net.url; import java.net.urlconnection; import javax.net.ssl.httpsurlconnection; public class testa { public static void main(string[] args) throws ioexception { string nextline = ""; url url = null; urlconnection urlconn = null; inputstreamreader instream = null; bufferedreader buff = null; try{ url = new url("https://kickass.to"); urlconn = url.openconnection(); ((httpsurlconnection) urlconn).sethostnameverifier(new verifier()); instream = new inputstreamreader(urlconn.getinputstream()); buff= new bufferedreader(instream); while(nextline != null){ nextline = buff.readline(); system.out.println(nextline); } }catch(malformedurlexception e){ system.out.println("please check url:" + e.tostring() ); } catch(ioexception e1){ system.out.println("can't read internet: "+ e1.tostring() ); } } }
hey, want source code of website, code works when use on other website when on www.kickass.to, response encoded or , looks
iÞŠpÃ2÷4rqy"pc‚q‚ßÑĶvnæö2”cnä.>*‰˜›m(Ïú¿p*s²™„j.û’›tÔÓµÄ鸘aȺ3ÛtyÜè¾eúm9ìbq.n‚+ô"§€¾aêty.¾ƒàj4gœ9ðõaˆopz–¡¹‹Ìo÷9íyh´4½ ÷ ¾ÏÀ|«m?e©Û”Þc\ñ°³%?øó"y„&Ãixrn¾ç\-ÛÚ~>
does know how can source code of kickass.to?
if inspect response headers, you'll notice contain
content-encoding:gzip
if inspect source code of page, you'll notice charset utf8.
so need read stream using
instream = new inputstreamreader(new gzipinputstream(urlconn.getinputstream()), standardcharsets.utf_8);
Comments
Post a Comment