Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Axios returns Network Error in a React Native app on iPhone or the iOS Simulator

ErrorAxiosError: Network Error

Short answer

A Network Error means iOS stopped the request before any HTTP answer came back. CORS is not involved in a native app. The three iOS-only causes are App Transport Security refusing a plain http URL, local network access denied on a real iPhone, and an https server whose certificate fails the checks.

  • Applies to React Native 0.8x, axios 1, iOS 17 and later, Xcode 26
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Log the code and whether any response arrived. An error without a response means the request never completed, so the status code and the body are not available to read. Then note where it fails: simulator only, device only, or both. The causes below split along that line.

    axios.get(url).catch((error) => {
      console.log(error.code, error.message);
      console.log('server answered:', Boolean(error.response));
    });
  2. 2Match what you see, then jump to its fix

    1. 1The failing URL starts with http://, and it fails on the simulator and on a device alike. Switching the same address to https works.App Transport Security blocks a plain http URLFix
    2. 2The app reaches a server on your computer, such as 192.168.1.20 or a .local name, from the simulator but not from a phone.Local network access is denied on a real iPhoneFix
    3. 3The URL is https, and the request fails on the simulator and on the device, while the same URL opens in a desktop browser.The https server fails the certificate or ATS checksFix

What does the error look like?

  • AxiosError: Network Error
  • error.code is ERR_NETWORK and error.response is undefined
  • The same request works on Android, in a browser, or on the iOS Simulator and fails on an iPhone

Cause 1 of 3

App Transport Security blocks a plain http URL

1Check

iOS enforces App Transport Security, which requires https. The React Native networking guide says a cleartext URL needs an exception in Info.plist, and that you should name the one domain instead of switching ATS off for the whole app.

grep -rn "http://" src/ .env* 2>/dev/null

2Fix

Move the API to https. If that is not possible for a development server, add an exception for that single host.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>dev.example.com</key>
    <dict>
      <key>NSExceptionAllowsInsecureHTTPLoads</key>
      <true/>
    </dict>
  </dict>
</dict>

3Verify

Rebuild the iOS app, because Info.plist is a native file, and repeat the request.

npx react-native run-ios

Confirmed by reactnative.dev

Did this fix it?

Cause 2 of 3

Local network access is denied on a real iPhone

1Check

Apple says outgoing traffic to a local network address needs local network access, and the simulator does not support local network privacy, so only a device shows the problem. A local network means an interface such as Wi-Fi or Ethernet, not cellular or VPN. Look at the switch in Settings.

# on the iPhone:
# Settings > Privacy & Security > Local Network > your app
grep -n "NSLocalNetworkUsageDescription" ios/*/Info.plist

2Fix

Add NSLocalNetworkUsageDescription to Info.plist with a short reason, so iOS can ask. Then switch the app on under Local Network in Settings, and keep the phone on the same Wi-Fi network as your computer. When access is granted later, the system retries the connection by itself.

<key>NSLocalNetworkUsageDescription</key>
<string>The app talks to the development API on your local network.</string>

3Verify

Run the app on the phone, allow the Local Network prompt, and repeat the request.

npx react-native run-ios

Confirmed by developer.apple.com

Did this fix it?

Cause 3 of 3

The https server fails the certificate or ATS checks

1Check

Apple's nscurl tool runs the same checks ATS does and prints PASS or FAIL for each setting. If it fails even with arbitrary loads allowed, the certificate itself is the problem: it must match the server's DNS name and must not be expired, among other requirements.

/usr/bin/nscurl --ats-diagnostics --verbose https://api.example.com

2Fix

Fix the certificate or the server settings that nscurl reports, for example install a certificate that matches the host name and is still valid. Add an ATS exception for the domain only for something the server cannot change.

# after the server change, the first test in the output should show:
/usr/bin/nscurl --ats-diagnostics --verbose https://api.example.com

3Verify

The default configuration test in the nscurl output shows Result : PASS, and the app request succeeds.

/usr/bin/nscurl --ats-diagnostics --verbose https://api.example.com | grep Result

Confirmed by developer.apple.com

Did this fix it?

How do I stop it coming back?

  • Use https for every API address from the first day, including the development server.
  • Add the NSLocalNetworkUsageDescription text once, when the project is created, if the app is ever tested against a server on your computer.
  • Test every networking change on a real iPhone as well as the simulator.
  • Log error.code and error.response in one shared Axios error handler.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.