Java URLConnection 响应已编码

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 the URL:" +  e.toString() );
        } catch(IOException  e1){
            System.out.println("Can't read  from the Internet: "+ e1.toString() ); 
        }        
    }

 }

嘿,我想获取这个网站的源代码,当我在其他网站上使用它时,该代码有效,但当我在 www.kickass.to 上使用时,响应被编码或类似的东西,看起来像这样

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¾ç\-ÛÚ~>

有谁知道我怎样才能得到kickass.to的源代码?

如果您检查响应 headers,您会注意到它们包含

content-encoding:gzip

如果您检查页面的源代码,您会注意到字符集是 UTF8。

因此您需要使用

读取流
inStream = new InputStreamReader(new GZIPInputStream(urlConn.getInputStream()), StandardCharsets.UTF_8);