apisauce icon indicating copy to clipboard operation
apisauce copied to clipboard

Getting NETWORK_ERROR after upgrade react-native to v0.59.9

Open tkhatibi opened this issue 5 years ago • 19 comments

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 avatar Jun 25 '19 12:06 tkhatibi

@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?

ryanlntn avatar Jun 25 '19 18:06 ryanlntn

same error here

brenohq avatar Jun 25 '19 19:06 brenohq

Related to Android P, see https://github.com/facebook/react-native/issues/22375

thebylito avatar Jul 03 '19 17:07 thebylito

@thebylito Debug mode ok, unable to request network in release mode. fetch is ok

songxiaoliang avatar Sep 29 '19 09:09 songxiaoliang

@songxiaoliang i am facing the exact same issue, were you able to get a solution for it?

banwar960 avatar Apr 16 '20 08:04 banwar960

@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 avatar Apr 16 '20 14:04 thebylito

@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

banwar960 avatar Apr 17 '20 06:04 banwar960

I am also having this problem in a production build and have tried adding the line android:usesCleartextTraffic="true".

rhunter18 avatar Jun 26 '20 11:06 rhunter18

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
      }

augini avatar Aug 27 '20 02:08 augini

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

Vincetroid avatar Feb 18 '21 18:02 Vincetroid

has anyone facing this issue tried this solution : const audio = { uri: 'file://' + this.recorder.fsPath, type: 'video/mp4', name: filename }

absmugz avatar May 24 '21 18:05 absmugz

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",

sagargulati avatar Jun 02 '21 12:06 sagargulati

Do you face this issue on real device on debug mode?

chakrihacker avatar Jun 05 '21 11:06 chakrihacker

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

sagargulati avatar Jun 22 '21 13:06 sagargulati

Can someone let me know:

  1. if this issue is still happening with the latest RN
  2. if you've found any solutions

Thanks!

jamonholmgren avatar Aug 20 '21 17:08 jamonholmgren

Same problem here, but for method get and post is normal, and always error NETWORK for method put and patch

YopiRagil avatar Feb 21 '22 12:02 YopiRagil

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());
}

pnthach95 avatar Mar 01 '22 06:03 pnthach95

Try to run android studio as Administrator, then run Emulator and retry to send your request

idimac avatar Apr 22 '22 13:04 idimac