我希望能够得到一个发送Content-Encoding: gzip头部的网页,但是我不知道如何读取它。
我的代码是:
try {
URLConnection connection = new URL("http://jquery.org").openConnection();
String html = "";
BufferedReader in = null;
connection.setReadTimeout(10000);
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
html+=inputLine+"\n";
}
in.close();
System.out.println(html);
System.exit(0);
} catch (IOException ex) {
Logger.getLogger(Crawler.class.getName()).log(Level.SEVERE, null, ex);
}
输出结果看起来非常混乱..(我无法在这里粘贴,一种符号..)
我认为这是压缩内容,如何解析它?
注意: 如果我将jquery.org更改为jquery.com(不发送该标头),我的代码就能正常工作。
x-gzip
。但非常感谢。 - Crocode