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