2016-06-27 88 views
9

Attualmente sto lavorando w/react nativo su Android. Sto facendo richieste API usando fetch() ma le richieste mi danno un errore di richiesta di rete, che è dovuto al fatto che l'endpoint non ha un certificato SSL. Sono stato in grado di rimuovere questo controllo su iOS modificando alcuni file xcode. C'è un modo per ignorare i controlli dei certificati SSL su Android?Ignora controllo certificato SSL su Android React Native

+2

Qualche soluzione per questo? – Upendra

risposta

1
/** 
* Disables the SSL certificate checking for new instances of {@link HttpsURLConnection} This has been created to 
* aid testing on a local box, not for use on production. 
*/ 
private static void disableSSLCertificateChecking() { 
    TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { 
     public X509Certificate[] getAcceptedIssuers() { 
      return null; 
     } 

     @Override 
     public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { 
      // Not implemented 
     } 

     @Override 
     public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { 
      // Not implemented 
     } 
    } }; 

    try { 
     SSLContext sc = SSLContext.getInstance("TLS"); 

     sc.init(null, trustAllCerts, new java.security.SecureRandom()); 

     HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 
    } catch (KeyManagementException e) { 
     e.printStackTrace(); 
    } catch (NoSuchAlgorithmException e) { 
     e.printStackTrace(); 
    } 
} 

Abbiamo trovato questo qui: https://gist.github.com/aembleton/889392. Non troppo sicuro se funziona, ma è un inizio!

Problemi correlati