I am using the react native Fetch API to get JSON data from https://api.github.com/users/{username}
but the request fails with the following error message.
"TypeError: Network request failed {stack: (...), message: 'Network request failed'}".
I believe for https, sometimes you get NSURLAuthenticationChallenge. I am not sure how to implement this. Anyone have any idea about this?
Using FetchReact Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have used XMLHttpRequest or other networking APIs before. You may refer to MDN's guide on Using Fetch for additional information.
It's just that simple! Start your app as usual but don't forget to give an IP address and a port, this will help you solve the Network Request Failed error. And on your mobile app, make sure to use the correct URL in your request. Make sure that CORS is enabled on your backend to avoid errors related to CORS.
Most of time , when network request failed error occurred, clearing the app cache will resolve the issue. So, To fix Instagram network request failed issue, clear Instagram app cache. To clear the Instagram App cache, For Android users, Go to settings >> Find Instagram App >> Tap on clear cache.
A network request is an HTTP request from your mobile app to a server-side application. The iOS Agent detects network requests when the underlying implementation is handled by the NSURLConnection or NSURLSession classes.
If you are using iOs you may need to do the following:
You must enable your AppTransportSecurity
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
or
in the Info.plist.
For Android ensure that you have added permission to use INTERNET in the AndroidManifest.xml.
<uses-permission android:name="android.permission.INTERNET" />
Can you provide an snippet of your fetch
code?
Generally, a fetch
statement is written like:
fetch(requestURL)
.then( (response) => response.json() )
.then( (data) => {
this.setState({data: data});
})
.catch( (error) => console.log(error) )
.done();
Catching the error will allow the program to proceed without crashing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With