-2
我在https://的android APP URL中調用webservice函數。但我得到錯誤信息連接到「https://something.net」拒絕。有人可以幫我嗎?提前致謝。帶有https://的Android URL被拒絕
我在https://的android APP URL中調用webservice函數。但我得到錯誤信息連接到「https://something.net」拒絕。有人可以幫我嗎?提前致謝。帶有https://的Android URL被拒絕
使用下面的方法創建HttpClient類對象時。
例如:HttpClient httpClient = getNewHttpClient();
public HttpClient getNewHttpClient() {
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
MySSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
return new DefaultHttpClient(ccm, params);
} catch (Exception e) {
return new DefaultHttpClient();
}
}
你使用API 23嗎?請提供更多信息。另外,發佈完整的Logcat來檢查真正的問題。 –
您應該使用HttpsURLConnection:http://developer.android.com/reference/javax/net/ssl/HttpsURLConnection.html –