2

こんにちは私はサーバーがgzip圧縮をサポートしているかどうかを評価する必要があります。

したがって、リクエストでgzipをAccept-Encodingとして設定し、サーバーの応答に「Content-Encoding:gzip」が含まれているかどうかを評価します。

ただし、HTTPURLConnectionを使用してこれを行う方法についてはよくわかりません。特に、応答についてConnectionオブジェクトにクエリを実行する場合。私は現在:

HttpURLConnection con = (HttpURLConnection) feedurl.openConnection();
    con.setRequestProperty("Accept-Encoding", "gzip");
    System.out.println("Current Accept-Encoding: "+con.getRequestProperty("Accept-Encoding"));
    //check the response for the content-size
    float feedsize = con.getContentLength()/1024f;
    //the server uses transfer-encoding=chunked and does not specify
    //a content length
    if(con.getContentLength()==-1)
    {
        //count the content size manually
                    CountingInputStream counter = new CountingInputStream(con.getInputStream());
        while(counter.read()!=-1)
        {}
        feedsize=counter.getCount()/1024f;
    }
    con.disconnect();
4

1 に答える 1

3

このOReillyの記事をご覧ください。リクエストを生成する方法と、レスポンスに問い合わせて、返される内容に応じて適切なストリーム(通常またはgzip圧縮)を作成する方法を示しています。

于 2009-11-05T15:00:10.903 に答える