So I've been trying to read the html code from kickass.to(it works fine on other sites) but all I get is some weird gibberish.
My code:
BufferedReader in = new BufferedReader(
new InputStreamReader(new URL("http://kickass.to/").openStream()));
String s = "";
while ((s=in.readLine())!=null) System.out.println(s);
in.close();
For example:

Does anyone knows why it does that?
thanks!
解决方案
The problem here is a server that is probably not configured correctly, as it returns its response gzip compressed, even if the client does not send an Accept-Encoding: gzip header.
So what you're seeing is the compressed version of the page. To decompress it, pass it through a GZIPInputStream:
BufferedReader in = new BufferedReader(
new InputStreamReader(
new GZIPInputStream(new URL("http://kickass.to/").openStream())));
Java读取网页代码乱码问题解决
博客讲述使用Java读取kickass.to网页代码时出现乱码的问题。代码读取其他网站正常,但该网站返回乱码。原因是服务器配置可能有误,即便客户端未发送Accept - Encoding: gzip头,服务器仍返回gzip压缩响应。解决方案是使用GZIPInputStream进行解压缩。
1131

被折叠的 条评论
为什么被折叠?



