我遇到了一个问题,无法从Android设备调用https。请问有谁能提供连接到https服务器的步骤帮助我吗?
我尝试使用https连接到Google并且可以正常工作,但是当我尝试连接到本地服务器时,出现了问题。
- want to connect a RESTful web service with https
want to connect a SOAP based web service developed using JAX-WS with https.
Code to connect with RESTFul
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, 443)); SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry); DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams()); // Set verifier HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier); // Example send http request //final String url = "https://encrypted.google.com/"; final String url = "https://ipaddress:8181/RESTTest/cars"; HttpPost httpPost = new HttpPost(url); try{ HttpResponse response = httpClient.execute(httpPost); System.out.println(response); }catch(Exception e){ e.printStackTrace(); }
its working fine for google but not working for my server and it's giving
javax.net.ssl.SSLException: Not trusted server certificate
Code for connect with SOAP:
public String getString(final String methodName, Map<String, Object> params) throws Exception { HttpTransportSE httpsTransportSE = new HttpTransportSE("https://ipaddress:8181/BankingWS/banking?wsdl"); try { SoapObject request = new SoapObject("https://test/", methodName); if(params != null && params.size() > 0){ Set<String> keys = params.keySet(); Iterator<String> iterator = keys.iterator(); while(iterator.hasNext()){ String key = iterator.next(); request.addProperty(key, params.get(key)); key = null; } } SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.setOutputSoapObject(request); TrustManagerManipulator.allowAllSSL(); httpsTransportSE.call(methodName, envelope); SoapPrimitive sp = (SoapPrimitive) envelope.getResponse(); return sp.toString(); } catch (Exception exception) { System.out.println(exception.toString()); throw exception; } }
In above code using the TrustManagerManipulator from following link: http://abhinavasblog.blogspot.com/2011/07/allow-untrusted-certificate-for-https.html
SoapFault - faultcode: 'S:Client' faultstring: 'Cannot find dispatch method for {test.WSEndPointPort}authenticate' faultactor: 'null' detail: null
请帮忙解决这个问题,因为我无论如何都无法从安卓设备上调用https :(
非常感谢您的时间和努力。
谢谢, Ishan