0

Hello Developers, thanks for being helpful on all-time.

I'm working on a project it's working fine on Web Navigator Chrome,

but when I build the Android App using react-native, I found that I can't send requests to my server with any of Axios or fetch.

catch is always send Error : Network Error, but it's working fine with other servers here's some Screenshots :

my SERVER

other SERVER

I can't figure this out, so I expect some help from u guys.

oboualla
  • 33
  • 9

2 Answers2

0

Add this to your android/app/src/main/AndroidManifest.xml and below permission is used for accessing ConnectivityManager.

 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Rohit Aggarwal
  • 1,048
  • 1
  • 14
  • 32
  • yes, I have add this attribute too. but stil does not work – oboualla Aug 26 '21 at 16:01
  • i can fetch from other servers but not mine. – oboualla Aug 26 '21 at 16:03
  • Are you using localhost sever for this ? If yes, then try replacing localhost with 10.0.2.2. – Rohit Aggarwal Aug 26 '21 at 16:04
  • no it's https sub domain, can the problem come from the server ? but it's working fine on localhost i try it – oboualla Aug 26 '21 at 16:12
  • Can't really say if the problem is from server. [This](https://stackoverflow.com/questions/59600004/network-error-when-use-axios-in-react-native) and [this](https://github.com/axios/axios/issues/3192) can help you. – Rohit Aggarwal Aug 27 '21 at 03:07
  • thanks for your help, I try my best to fix it but I didn't, I am sure now the problem comes from the server for security reasons. each of ''/var/log/apache2/error.log" or ''var/log/apache2/access.log" does not have any trace about the request that i hv sent. – oboualla Aug 28 '21 at 02:40
0

I had this same problem before on Android with React Native.

Here are the steps that I did when debugging it:

  1. Try to use Postman to check if your endpoint is working.
  2. I was using GraphQL so I tested using fetch and axios to see if it returns the same network error.
  3. Test on iOS to see if it works or not.

After I did the above, since I deployed my API app on my own server. I pointed my graphql request to my public IP (http://xxx.xxx.xxx.xxx/graphql) and it works. You might need to add android:usesCleartextTraffic = "true" to your AndroidManifest.xml to make request to http url.

I finally figured out that it was a problem with my SSL certificate that was installed on my domain. I re-installed it back with proper certificate.pem and intermediate.pem and my problem is fixed.

Rasyue
  • 60
  • 1
  • 9
  • may the problem is come from SSL on my case too, but we figure out another solution is to link the website with another domain and then it's work. – oboualla Oct 30 '21 at 18:08