1

次のコードを使用してメソッドを複数回実行すると、期待どおりの GZIP で応答が返されることが数回あり、まったく異なる応答が返されることもあります (非 GZIP ページが見つかりません)。ただし、Mozilla または IE を使用して同じ URL を複数回ダウンロードすると、一貫して同じ GZIP 応答が得られます。

これはアクセスしようとしているサーバーのエラーですか、それとも一貫した応答を得るためにパラメーターを設定する必要がありますか?

ダウンロードしようとしているのは以下のURLですが、教えていただけますか?

public static byte[] dowloadURL(URL urlToDownload) {

    InputStream iStream = null;
    byte[] urlBytes = null;

    try {

        //HttpClient httpClient = new HttpClient();
        org.apache.http.client.
        HttpClient httpClient = new DefaultHttpClient();


        HttpGet httpget = new HttpGet(urlToDownload.toString());

        HttpResponse response  = httpClient.execute(httpget);

        iStream = response.getEntity().getContent();

        urlBytes = IOUtils.toByteArray(iStream);
        String responseString = new String(urlBytes);
        System.out.println(" >>> The response  string for " +urlToDownload.toString()+  " is "   +responseString);

    } catch (IOException e) {
        System.err.printf("Failed while reading bytes from %s: %s",
                urlToDownload.toExternalForm(), e.getMessage());
        e.printStackTrace();
        // Perform any other exception handling that's appropriate.
    } finally {
        if (iStream != null) {
            try {
                iStream.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    return urlBytes;
}
4

0 に答える 0