CopyPastor

Detecting plagiarism made easy.

Score: 0.806962251663208; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2021-04-13
by Shishir Aithal

Original Post

Original - Posted on 2020-02-07
by user



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Step1 : create a java file ex: 'CustomClientFactory' inside directory app > Java > com > (your_app_name) > CustomClientFactory.java
Inside that java file add the following code:
import com.facebook.react.modules.network.OkHttpClientFactory; import com.facebook.react.modules.network.OkHttpClientFactory; import com.facebook.react.modules.network.OkHttpClientProvider; import com.facebook.react.modules.network.ReactCookieJarContainer;
import java.security.cert.CertificateException; import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager;
import okhttp3.CipherSuite; import okhttp3.ConnectionSpec; import okhttp3.OkHttpClient; import okhttp3.TlsVersion;
import static android.content.ContentValues.TAG;
public class CustomClientFactory implements OkHttpClientFactory { private static final String TAG = "OkHttpClientFactory"; @Override public OkHttpClient createNewNetworkModuleClient() { try { // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { }
@Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { }
@Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[]{}; } } };
// Install the all-trusting trust manager final SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // Create an ssl socket factory with our all-trusting manager final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();


OkHttpClient.Builder builder = new OkHttpClient.Builder() .connectTimeout(0, TimeUnit.MILLISECONDS).readTimeout(0, TimeUnit.MILLISECONDS) .writeTimeout(0, TimeUnit.MILLISECONDS).cookieJar(new ReactCookieJarContainer()); builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]); builder.hostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } });
OkHttpClient okHttpClient = builder.build(); return okHttpClient; } catch (Exception e) { Log.e(TAG, e.getMessage()); throw new RuntimeException(e); } }
}
and inside your MainApplication.java add the following:
@Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); OkHttpClientProvider.setOkHttpClientFactory(new CustomClientFactory()); //add this line. }
Found the above solution from : [Similar issue][1]
And it worked fine for me. As per I understand, we write this file to Install the all-trusting trust managers and asking the app to allow 'https' api





[1]: https://stackoverflow.com/questions/36289125/react-native-fetch-from-https-server-with-self-signed-certificate
I am also faced the same issue in android. Finally i found the solution for this issue.
<!-- language: java -->
import com.facebook.react.modules.network.OkHttpClientFactory; import com.facebook.react.modules.network.OkHttpClientFactory; import com.facebook.react.modules.network.OkHttpClientProvider; import com.facebook.react.modules.network.ReactCookieJarContainer; import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import okhttp3.CipherSuite; import okhttp3.ConnectionSpec; import okhttp3.OkHttpClient; import okhttp3.TlsVersion; import static android.content.ContentValues.TAG; public class CustomClientFactory implements OkHttpClientFactory { private static final String TAG = "OkHttpClientFactory"; @Override public OkHttpClient createNewNetworkModuleClient() { try { // Create a trust manager that does not validate certificate chains final TrustManager[] trustAllCerts = new TrustManager[]{ new X509TrustManager() { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[]{}; } } }; // Install the all-trusting trust manager final SSLContext sslContext = SSLContext.getInstance("SSL"); sslContext.init(null, trustAllCerts, new java.security.SecureRandom()); // Create an ssl socket factory with our all-trusting manager final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); OkHttpClient.Builder builder = new OkHttpClient.Builder() .connectTimeout(0, TimeUnit.MILLISECONDS).readTimeout(0, TimeUnit.MILLISECONDS) .writeTimeout(0, TimeUnit.MILLISECONDS).cookieJar(new ReactCookieJarContainer()); builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]); builder.hostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); OkHttpClient okHttpClient = builder.build(); return okHttpClient; } catch (Exception e) { Log.e(TAG, e.getMessage()); throw new RuntimeException(e); } } } and inside our Android application MainApplication.java
<!-- language: java -->
@Override public void onCreate() { super.onCreate(); SoLoader.init(this, /* native exopackage */ false); OkHttpClientProvider.setOkHttpClientFactory(new CustomClientFactory()); //add this line. }
Its work for me. May be it will help to all.

        
Present in both answers; Present only in the new answer; Present only in the old answer;