Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create an https Connection?
    primarykey
    data
    text
    <p>My code works for http, but not https. I'm trying to make <code>Https connections</code> on the Android phones, using HttpClient. Trouble is that i keep getting <code>net.ssl.SSLPeerUnverifiedException: No peer certificate</code>. and <code>Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.</code></p> <p>Here is the relavent code for the Custom HttpClient.</p> <pre><code>public static HttpClient getNewHttpClient() { HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.DEFAULT_CONTENT_CHARSET); HttpProtocolParams.setUseExpectContinue(params, true); SchemeRegistry schReg = new SchemeRegistry(); schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443)); ClientConnectionManager conMgr = new ThreadSafeClientConnManager(params, schReg); DefaultHttpClient http = new DefaultHttpClient(conMgr, params); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("name", "pass"); AuthScope authScope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); http.getCredentialsProvider().setCredentials(authScope, credentials); return http; } </code></pre> <p>this is the code for getting information from the server </p> <pre><code>public static void Get() { HttpClient http = getNewHttpClient(); HttpResponse response; try { HttpGet httpost = new HttpGet(url); response = http.execute(httpost); BufferedReader in = null; Log.i(TAG, "resp-" + response); in = new BufferedReader(new InputStreamReader(response.getEntity() .getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); String page = sb.toString(); Log.i(TAG, "res=" + sb.toString()); tv.setText(page); } catch (ClientProtocolException e) { Log.i(TAG, "ClientProtocolException=" + e); e.printStackTrace(); } catch (IOException e) { Log.i(TAG, "ClientProtocolException=" + e); e.printStackTrace(); } } </code></pre> <p>Any thoughts?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload