apisauce
apisauce copied to clipboard
Getting NETWORK_ERROR after upgrade react-native to v0.59.9
This is error stack:
"Error: Network Error
at createError (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:202353:17)
at XMLHttpRequest.handleError (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:202261:16)
at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30335:27)
at XMLHttpRequest.setReadyState (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30088:20)
at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:29915:16)
at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:30025:47
at RCTDeviceEventEmitter.emit (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:5939:37)
at MessageQueue.__callFunction (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:5232:44)
at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:4989:17
at MessageQueue.__guard (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:5186:13)"
@tkhatibi From that stack trace it looks like it's failing on a native level and not within apisauce. Are you able to make a request just using fetch or do you get a network error there as well?
same error here
Related to Android P, see https://github.com/facebook/react-native/issues/22375
@thebylito Debug mode ok, unable to request network in release mode. fetch is ok
@songxiaoliang i am facing the exact same issue, were you able to get a solution for it?
@songxiaoliang i am facing the exact same issue, were you able to get a solution for it? Related to Android P, see facebook/react-native#22375 and https://github.com/facebook/react-native/issues/22375#issuecomment-481251422
@thebylito android:usesCleartextTraffic="true" is added in my manifest file but i am still getting network_error on my live build. The debug build works fine but not the live build
I am also having this problem in a production build and have tried adding the line android:usesCleartextTraffic="true".
THE SOLUTION is: on Android you need to specify the file path with file:// as prefix. So do like this:
const audio = {
uri: 'file://' + this.recorder.fsPath,
type: 'video/mp4',
name: filename
}
This is happening to me with Axios on debug mode with the next set up:
"axios": "^0.21.1", "react": "16.13.1", "react-native": "~0.63.4",
Fetch built-in works well
has anyone facing this issue tried this solution :
const audio = { uri: 'file://' + this.recorder.fsPath, type: 'video/mp4', name: filename }
Having the same issue. Works fine with Android API 30 with Google Pixel Emulator on DEV but when make bundleRelease
and use. Shows "network error"
"react": "17.0.1",
"react-native": "0.64.1",
"apisauce": "^2.1.1",
Do you face this issue on real device on debug mode?
Yes. As I found out on log cat, the first issue was with the API Level itself. Then the main issue turns out to be with support for TLS. The current API levels support up to TLS 1.2 while we were using TLS 1.3 as the default SSL protocol.
So the FIX should be major with API level and TLS support with a minimum 1.0 or 1.1
Can someone let me know:
- if this issue is still happening with the latest RN
- if you've found any solutions
Thanks!
Same problem here, but for method get and post is normal, and always error NETWORK for method put and patch
Solution for my case is to ignore certificate. I update OkHttpClient
inside onCreate()
in MainApplication.java
, credit to this gist
@Override
public void onCreate() {
super.onCreate();
OkHttpClientProvider.setOkHttpClientFactory(() -> {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@SuppressLint("TrustAllX509TrustManager")
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType)
throws CertificateException {
}
@SuppressLint("TrustAllX509TrustManager")
@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();
builder.sslSocketFactory(sslSocketFactory, (X509TrustManager) trustAllCerts[0]);
builder.hostnameVerifier(new HostnameVerifier() {
@SuppressLint("BadHostnameVerifier")
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
} catch (Exception e) {
//
}
return builder
.cookieJar(new ReactCookieJarContainer())
.build();
});
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}
Try to run android studio as Administrator, then run Emulator and retry to send your request