Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting NETWORK_ERROR after upgrade react-native to v0.59.9 #218

Open
tkhatibi opened this issue Jun 25, 2019 · 19 comments
Open

Getting NETWORK_ERROR after upgrade react-native to v0.59.9 #218

tkhatibi opened this issue Jun 25, 2019 · 19 comments
Labels

Comments

@tkhatibi
Copy link

tkhatibi commented Jun 25, 2019

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)"
@ryanlntn
Copy link
Member

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

@brenohq
Copy link

brenohq commented Jun 25, 2019

same error here

@thebylito
Copy link

Related to Android P, see facebook/react-native#22375

@songxiaoliang
Copy link

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

@banwar960
Copy link

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

@thebylito
Copy link

@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
facebook/react-native#22375 (comment)

@banwar960
Copy link

@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

@rhunter18
Copy link

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

@augini
Copy link

augini commented Aug 27, 2020

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
      }

@Vincetroid
Copy link

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

@absmugz
Copy link
Collaborator

absmugz commented May 24, 2021

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

@sagargulati
Copy link

sagargulati commented Jun 2, 2021

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

@chakrihacker
Copy link
Collaborator

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

@sagargulati
Copy link

sagargulati commented Jun 22, 2021

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

@jamonholmgren
Copy link
Member

Can someone let me know:

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

Thanks!

@YopiRagil
Copy link

YopiRagil commented Feb 21, 2022

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

@pnthach95
Copy link

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

@idimac
Copy link

idimac commented Apr 22, 2022

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

@saaspeter
Copy link

for my case, my call works well in IOS, but failed in android, after replace the localhost to 10.0.2.2 , it works. see : https://stackoverflow.com/questions/9808560/why-do-we-use-10-0-2-2-to-connect-to-local-web-server-instead-of-using-computer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests