I used to use a custom TrustManager that was talking about here to do this
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
MyXMLHandler mHandler = new MyXMLHandler();
xr.setContentHandler(mHandler);
xr.parse(new InputSource(buildUrlString()));
(where buildUrlString () returns a string containing https: // url to call), which works fine. However, I now want to be able to send the same url Accept-Encoding header for gzip compression. I can do it like this
HttpUriRequest request = new HttpGet(buildUrlString());
request.addHeader("Accept-Encoding", "gzip");
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
InputStream instream = response.getEntity().getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if ((contentEncoding != null)
&& contentEncoding.getValue().equalsIgnoreCase("gzip"))
{
instream = new GZIPInputStream(instream);
}
xr.parse(new InputSource(instream));
but this returns an "Invalid server certificate" error that I want to ignore. How do I do HTTPS? Alternatively, is there a better way to do this? (And is there something I need to check to make sure the phone can actually accept gzipped web pages that I can say?)
source
share