Content-Encoding:gzipヘッダーを送信するWebページを要求しましたが、その読み取り方法が行き詰まりました。
私のコード:
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に変更すると(そのヘッダーは送信されませんが、コードは正常に機能します)