Home > Article > Web Front-end > Why am I getting a \"Network Request Failed\" error in React Native fetch() and how do I fix it?
When working with React Native, developers may encounter network request errors, specifically with the fetch() method. One common error is "Network Request Failed."
In a recent instance, a user created a new React Native project (version 0.29.1) and included a fetch request within the render method. Despite targeting the public Facebook demo movie API, the request resulted in a "Network Request Failed" error. The stack trace provided little information for debugging, and console-based network request debugging was not possible.
This error stems from iOS's default security settings, which prohibit HTTP requests unless explicitly allowed. To rectify the issue, add the following to your project's info.plist file:
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict>
By adding this configuration, you explicitly allow your React Native app to make HTTP requests. This resolves the "Network Request Failed" error and allows you to continue working with network requests effectively.
The above is the detailed content of Why am I getting a \"Network Request Failed\" error in React Native fetch() and how do I fix it?. For more information, please follow other related articles on the PHP Chinese website!