以前,我用定義TrustManager談到here爲此HTTPGET /客戶端和HTTPS
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
MyXMLHandler mHandler = new MyXMLHandler();
xr.setContentHandler(mHandler);
xr.parse(new InputSource(buildUrlString()));
(其中buildUrlString()返回一個包含HTTPS的字符串:// URL調用)的正常工作。但是,現在我想能夠發送相同的url用於gzip壓縮的Accept-Encoding標頭。我是這樣做的
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));
但帶回的「不信任的服務器證書」的錯誤,我想忽略。我如何使它做HTTPS?或者,有沒有更好的方法來做到這一點? (而且是有什麼,我需要先進行檢查,以確保手機真的能接受,我說它能對gzip壓縮的網頁?)
哦,整齊,謝謝! – 2011-05-05 09:53:51
我還沒有測試過這個解決方案,但是它受到Bob Lee博客文章的啓發http://blog.crazybob.org/2010/02/android-trusting-ssl-certificates.html – Jcs 2011-05-05 09:56:00