1

I have JSON service exposed on http and https sites (same IIS server). Using this code, when calling http url I'm getting gziped response, but calling https response is not gziped. HTTPS is retutning gziped content and proper headers (in this case wanted header is Content-Encoding) on another apps that are consuming same site.

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();
        }
    }

Does anyone have Idea what is an Issue here, or should I use another approach? contentEncoding header is null

Avicena00
  • 355
  • 1
  • 5
  • 24
  • If the headers say it is gzippped, either (a) it is gzipped or (b) the server has a bug. Nothing you can do about (b) from the client end. – user207421 Feb 25 '15 at 09:18
  • server is returning header Content-Encoding on apps that consuming it, but not on Android device so server is fine – Avicena00 Feb 25 '15 at 10:07

0 Answers0