I've create a self-signed http & self-sign certificate https server in one app by using express.js
Fetch is working fine when I send the request to http port.
But it is fail when I send the same request to https port.
I understand it might be due to self-sign certificate, but is there any way to ignore error due to self-sign certificate in android ?
fetch('https://192.168.1.21/Register/', { //not working
fetch('http://192.168.1.21:3000/Register/', { //working fine
//the rest of the code is the same.
I'm facing the same problem. Is there a solution to this?
Also I'm facing this problem
same here
I have the same issue on iOS. I can't allow self-signed certificates for some reason.
@dave-irvine For iOS, just make an extension for RCTHTTPRequestHandler and implement delegate method - (void)URLSession:(NSURLSession *)session didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler.
This will not break the source code of React Native, also verify you certificates as you want.
facing the same problem, need help!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.
Also I'm facing this problem
Also I'm facing this problem. please help me to solve this issue
Before [1] this was possible by customizing the okhttp client on android. It's no longer possible.
[1] https://github.com/facebook/react-native/commit/0a71f48b1349ed09bcb6e76ba9ff8eb388518b15#diff-f8703d50cf5af4c06824e2928dddb500
It's a need this fetch API allow self-signed requests. As a workaround, I'm using this package react-native-fetch-blob to make self-signed requests. Please, implement this feature!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions.
Still facing this issue in latest RN Version ==
Same issue here, Generating a debug APK or using react-native run-android I able to fetch the HTTPS URL, but unfortunately with release APK it always timeout (trying to get some logcat logs to help with this issue), I think it as something relates to SSL Exception by Android platform.
OS: Windows 10
Node: 9.5.0
Yarn: 1.6.0
npm: 6.0.0
Watchman: 4.9.1
Xcode: N/A
Android Studio: Not Found
react: 16.3.1 => 16.3.1
react-native: ^0.55.4 => 0.55.4
Hi, I have this problem only in one specify WI-FI connection, but in the same network with my computer I am able to access the HTPPS URl and having GET,POST, all working via browser/postman.
I don't know what can be.
Did you solve it?
In my case, it was a backend problem with certificates that cause Android not getting any responses.
I have same problem with android sdk < 21
My API endpoints is under cloudflare and all requests failed with network request failed error message when i send any request to https://myCloudflireDomain
Same request works as expected on iOS and Android sdk > 21.
This should be considered as bug in this fetch in reason of my API endpoint can be opened in default android browser on device with android 4.4.2 for example.
Here is what i can observe so far:
_Android 4.4.2:_
fetch('https://myCloudflireDomain') network request failed
fetch('https://wikipedia.org/') this is works
But! Both domains will work in default browser.
Why it is possible to open https://myCloudflireDomain in android browser, but fetch rase an exception?
PS: SSL cert is definitely valid

Environment
https://github.com/MadGeorge Are you able to solve this issue. I face the same problem as you. Does anyone have solution for this problem. Please help me, thank you!
A work around that I use for this issue, is to use react-native-fetch-blob.
Because there's an option in RNFetchBlob to ignore security.certification.
We have to set trusty in the config part.
Below is the complete sample:
RNFetchBlob.config({
trusty: true,
timeout: 5000
})
.fetch(
"POST",
"https://192.168.2.10/testService",
{
Accept: "text/xml",
"Content-Type": "application/json"
},
JSON.stringify({
key: keyValue
})
)
.catch(err => {
console.log("err: ", err);
alert("Network Error");
});
But above code will also give this error:
java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
The 2nd work around as per link:
https://github.com/joltup/rn-fetch-blob/pull/49/commits/48f18c8b8a7694a3bd048843e88713ec5d186d45
is to edit: /node_module/react-native-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
and comment: client.sslSocketFactory(new TLSSocketFactory());
@haily2706 no I鈥檓 not. I turned off Cloudflare option to force domain to https this is only solution I found.
I am facing some problem. My https API was working. but after implementing a self signed certificate for https at the server, https APIs are failing withNetwork request failed.
After switching to 0.57 + the problem is gone
I am facing the same issue. my https server working fine with postman using a self-signed certificate. But unable to get any response from the server when using the react-native android app.
Any Suggestions?
I added the following code to the onCreate method of MainActivity and everything worked as it should.
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.security.ProviderInstaller;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
ProviderInstaller.installIfNeeded(getApplicationContext());
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
UPDATE
Sometimes I get broken JSON in the response anyway, so I added the rn-fetch-blob library with isTrusted: true option to the solution as mentioned above. The problems disappeared completely.
Dobrynia, Thanks for the suggestion, while I am trying this code, I am getting compilation errors, do I have to install any package for google libraries in react native, please suggest
Task :app:compileDebugJavaWithJavac FAILED
C:\Users\Hemu\Downloads\Prototype-master\Prototype-master\newClient\android\app\src\main\java\com\newclient\MainActivity.java:9: error: package com.google.android.gms.common does not exist
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
^
C:\Users\Hemu\Downloads\Prototype-master\Prototype-master\newClient\android\app\src\main\java\com\newclient\MainActivity.java:10: error: package com.google.android.gms.common does not exist
import com.google.android.gms.common.GooglePlayServicesRepairableException;
^
C:\Users\Hemu\Downloads\Prototype-master\Prototype-master\newClient\android\app\src\main\java\com\newclient\MainActivity.java:11: error: package com.google.android.gms.security does not exist
import com.google.android.gms.security.ProviderInstaller;
^
C:\Users\Hemu\Downloads\Prototype-master\Prototype-master\newClient\android\app\src\main\java\com\newclient\MainActivity.java:25: error: cannot find symbol
protected void onCreate(@Nullable Bundle savedInstanceState) {
^
symbol: class Nullable
location: class MainActivity
C:\Users\Hemu\Downloads\Prototype-master\Prototype-master\newClient\android\app\src\main\java\com\newclient\MainActivity.java:29: error: cannot find symbol
ProviderInstaller.installIfNeeded(getApplicationContext());
^
symbol: variable ProviderInstaller
location: class MainActivity
C:\Users\Hemu\Downloads\Prototype-master\Prototype-master\newClient\android\app\src\main\java\com\newclient\MainActivity.java:30: error: cannot find symbol
} catch (GooglePlayServicesRepairableException e) {
^
symbol: class GooglePlayServicesRepairableException
location: class MainActivity
C:\Users\Hemu\Downloads\Prototype-master\Prototype-master\newClient\android\app\src\main\java\com\newclient\MainActivity.java:32: error: cannot find symbol
} catch (GooglePlayServicesNotAvailableException e) {
^
symbol: class GooglePlayServicesNotAvailableException
location: class MainActivity
7 errors
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 3s
28 actionable tasks: 1 executed, 27 up-to-date
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html
C:\Users\Hemu\Downloads\Prototype-master\Prototype-master\newClient>
same error, I use Cloudflare, my version of RN is 0.57.7 馃槩 @dobrynia don't compile , any fix?
@HEMANT8712 and @lahed, is there the
implementation 'com.google.android.gms:play-services-base:16.0.1' line in your android/app/build.gradle file, section dependencies?
@dobrynia don't work for me.
My solution: I configure Cloudflare to use http and https on my api, and everything else in https.
When android version is < 20 I used http else https
Hello there 馃憢 this issue has been reported for an old version of React Native. Ideally we'd like everyone to be using 0.59 (see the awesome changes it brought) but we know updating can be a pain. During 0.59 update, some changes were made to the android JSC, so it might have fixed this.
But please, if it's actually still an issue with 0.59 please comment below and we can reopen it. Even better, please send us a pull request with a fix 馃槉
Still an issue on react 0.59 for me.
My configuration is almost same as @MadGeorge
I have Cloudflare configured to force my domain to https. This works fine on Androids above 5.0 and iOS too, but fails on older Android devices.
Switching to http helps
I'm facing the same issue
I am facing same issue
I am facing same issue
try this
it works for me
same issue RN version 0.61.4
2020 and the same problem with axios :(
I solved my problem with axios by passing data anyway.
{ data: data || {} }
Most helpful comment
Still an issue on react 0.59 for me.
My configuration is almost same as @MadGeorge
I have Cloudflare configured to force my domain to https. This works fine on Androids above 5.0 and iOS too, but fails on older Android devices.
Switching to http helps