Sono di fronte a javax.net.ssl.SSLPeerUnverifiedException: Nessuna eccezione di peer certificate mentre si lavora con google place api nell'emulatore di Android. Qui di seguito è il mio url:javax.net.ssl.SSLPeerUnverifiedException: Nessun certificato peer mentre sto lavorando con google place api in android
https://maps.googleapis.com/maps/api/place/search/json?&location=28.632808,77.218276&radius=1000&sensor=false&key=AIzaSyC3y3fOMTqTkCjNNETQTCKustG7BRk_eVc
quando ho semplicemente, incollare sopra url nella barra degli indirizzi del browser, è semplice dà JSON string.So, penso che ci sia bisogno di alcuna autenticazione dei certificati.
Dopo aver fatto tanti googling e dedicato 2-3 giorni, ho utilizzato la classe SSLSocketFacory del pacchetto org.apache.http.conn.ssl.SSLSocketFactory per evitare errori del certificato peer.
sotto è il mio codice:
public static HttpClient wrapClient(HttpClient base) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
X509HostnameVerifier verifier = new X509HostnameVerifier() {
public void verify(String string, SSLSocket ssls) throws IOException {
}
public void verify(String string, X509Certificate xc) throws SSLException {
}
public void verify(String string, String[] strings, String[] strings1) throws SSLException {
}
public boolean verify(String string, SSLSession ssls) {
return true;
}
};
ctx.init(null, new TrustManager[]{tm}, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
ssf.setHostnameVerifier(verifier);
ClientConnectionManager ccm = base.getConnectionManager();
SchemeRegistry sr = ccm.getSchemeRegistry();
sr.register(new Scheme("https", ssf, 443));
return new DefaultHttpClient(ccm, base.getParams());
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
Sto usando Android API 16, e quando ho usato SSLSocketFactory costruttore (SSLSocketContext), eclissi dà errore compliation, così ho la ricerca molto e scaricare vaso avendo SSLSocketFactory (SSLSocketContext), che è "httpclient-4.1.1.jar" file.and ho anche ordinanza vaso nel progetto di percorso di generazione set, hanno creato più alto priority.Now sto ottenendo seguente avviso:
VFY:unable to resolve direct method 4253:Lorg/apache/http/conn/ssl/SSLSocketFactory.<init>
E seguendo una lunga traccia di errore causata da
java.lang.NoSuchMethodError : org.apace.http.conn.ssl.SSLSocketFactory.<init>
Per favore, aiutatemi non so, dove mi sbaglio.
accade su un dispositivo vero e proprio? Quale versione di Android sta emulando il tuo emulatore? L'utilizzo di un gestore di trust 'no check' è un'idea * pessima *, quindi non farlo. –
Il problema è stato risolto. Grazie mille stackoverflow.Il link sottostante ha risolto il mio problema. http://stackoverflow.com/questions/7622004/android-making-https-request/13485550#13485550 – ved
NON FARE QUESTO. SPEGNERE SSL È UN FORO DI SICUREZZA ENORME. Ci scusiamo per tutti i limiti. – Bishnu