1

http サイトと https サイト (同じ IIS サーバー) で JSON サービスを公開しています。このコードを使用すると、http url を呼び出すときに gzip された応答が得られますが、https 応答を呼び出すと gzip されません。HTTPS は、同じサイトを使用している別のアプリで、gzip されたコンテンツと適切なヘッダー (この場合、必要なヘッダーは Content-Encoding) を返します。

private InputStream execute(String url, int method, JSONObject jsonObject) throws ClientProtocolException, IOException {
        DefaultHttpClient httpsclient = new DefaultHttpClient();



        InputStream inStream = null;
        // Checking http request method type
        if (method == POST) {
            HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("Accept-Encoding", "gzip");
            httpPost.setHeader("Accept", "application/json");
            httpPost.setHeader("Content-type", "application/json; charset=utf-8");
            // adding post params
            if (jsonObject != null) {
                StringEntity entity = new StringEntity(jsonObject.toString(), HTTP.UTF_8);
                httpPost.setEntity(entity);
            }

            HttpResponse httpRes = httpsclient.execute(httpPost);
            inStream = httpRes.getEntity().getContent();

            Header contentEncoding = httpRes.getFirstHeader("Content-Encoding");
            if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
                return new GZIPInputStream(inStream);
            } else {

                return inStream;
            }
        } else if (method == GET) {
            throw new UnsupportedOperationException("GET not implemented yet.");
        } else {
            throw new UnsupportedOperationException();
        }
    }

ここで何が問題なのか、誰かが考えているのですか、それとも別のアプローチを使用する必要がありますか? contentEncoding ヘッダーが null です

4

0 に答える 0