Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected HttpClient constructClient() {
- HttpParams params = new BasicHttpParams();
- params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
- // use the debug proxy to view internet traffic on the host computer
- if (ABCApplication.isDebuggingProxy()) params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(ABCConstants.DEBUG_PROXY_HOST, ABCConstants.DEBUG_PROXY_PORT, "http"));
- // ignore ssl certification (due to signed authority not appearing on android list of permitted authorities)
- // see: http://blog.antoine.li/2010/10/22/android-trusting-ssl-certificates/
- SchemeRegistry registry = new SchemeRegistry();
- registry.register(new Scheme("http", new PlainSocketFactory(), 80));
- registry.register(new Scheme("https", new FakeSocketFactory(), 443));
- ClientConnectionManager cm = new SingleClientConnManager(params, registry);
- return new DefaultHttpClient(cm, params);
- }
- HttpURLConnection http = null;
- URL url;
- try {
- url = new URL("https:your domian");
- if (url.getProtocol().toLowerCase().equals("https")) {
- trustAllHosts();
- HttpsURLConnection https = (HttpsURLConnection) url.openConnection();
- https.setHostnameVerifier(DO_NOT_VERIFY);
- http = https;
- System.out.println("TEST:::"+convertStreamToString(http.getInputStream()));
- } else {
- http = (HttpURLConnection) url.openConnection();
- System.out.println("TEST:::"+convertStreamToString(http.getInputStream()));
- }
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- public void checkClientTrusted(X509Certificate[] chain,
- String authType) throws CertificateException {
- }
- public void checkServerTrusted(X509Certificate[] chain,
- String authType) throws CertificateException {
- }
- } };
- // Install the all-trusting trust manager
- try {
- SSLContext sc = SSLContext.getInstance("TLS");
- sc.init(null, trustAllCerts, new java.security.SecureRandom());
- HttpsURLConnection
- .setDefaultSSLSocketFactory(sc.getSocketFactory());
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement