【发布时间】:2012-02-24 08:40:37
【问题描述】:
我正在尝试从 https://....com:8455 链接获取内容,其中 “服务器的证书不受信任”。内容是:“测试”。
但我在 HttpResponse response = httpClient.execute(httpPost); 之后得到 NullPointerException。 我正在使用下一个代码:
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
DefaultHttpClient client = new DefaultHttpClient();
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme("https", socketFactory, 8455));
SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
final String url = "https://....com:8455";
HttpPost httpPost = new HttpPost(url);
try {
HttpResponse response = httpClient.execute(httpPost);
Log.v("data: ", HttpHelper.requestStr(response));
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
谁能帮帮我?
【问题讨论】: