What can I call a secure (SSL) web service in Android when Android does not see the certificate?

I am new to Android and I am struggling to call the SSL web service for Android app. My code is as follows:

Log.v("fs", "Making HTTP call...");
HttpClient http = new DefaultHttpClient();
HttpGet request = new HttpGet("https://example.com/api");

try {

    String response = http.execute(request, new BasicResponseHandler());
    Log.v("fs", response);

} catch (Exception e) {

    Log.v("fs", e.toString());
}

Output:

Making HTTP call...
javax.net.SSLPeerUnverifiedException: No peer certificate

Any suggestions for this work would be great.

I must note that this is a valid certificate. It is signed by an official certification authority.

+5
source share
5 answers

Do you check that the date and time for mobile devices are correct? If you use SSL and have your mobile phone in 1990, it will be back.

javax.net.SSLPeerUnverifiedException: no peer certificates

Hi

+2
source

. SSLSocketFactory SSL-, ThreadSafeClientConnManager. - - .

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("mxiss", SSLSocketFactory.getSocketFactory(), 443));

    HttpParams params = new BasicHttpParams();
    int timeoutConnection = 5000;
    HttpConnectionParams.setConnectionTimeout(params, timeoutConnection);
    int timeoutSocket = 10000;
    HttpConnectionParams.setSoTimeout(params, timeoutSocket);
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
    params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);

    _client = new DefaultHttpClient(cm, params);

, .

. -, .

Protocol mxiss = new Protocol("mxiss", new EasySSLProtocolSocketFactory(), 443);
Protocol.registerProtocol("mxiss", mxiss);

"https" "mxiss"

EasySSLProtocolSocketFactory org.apache.commons.httpclient.contrib.ssl. jar http://repo1.maven.org/maven2/ca/juliusdavies/not-yet-commons-ssl/0.3.11/not-yet-commons-ssl-0.3.11.jar .

+1
SchemeRegistry schemeRegistry = new SchemeRegistry(); 
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
schemeRegistry.register(new Scheme("mxiss", SSLSocketFactory.getSocketFactory(), 443));


HttpParams params = new BasicHttpParams(); 
int timeoutConnection = 5000; 
HttpConnectionParams.setConnectionTimeout(params, timeoutConnection); 
int timeoutSocket = 10000; 
HttpConnectionParams.setSoTimeout(params, timeoutSocket);

params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); 

params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean); 

params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); 

HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);


ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);

_client = new DefaultHttpClient(cm, params);
+1

, . Pls InstallCert.java, : http://blogs.oracle.com/andreas/entry/no_more_unable_to_find. . , , .
, .

0

, Get in HTTPS webservice. - POST .

-10

All Articles