question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Local Fetch GET Network Request Failing

See original GitHub issue

Description I’m trying to fetch data from my local api’s & getting “Network Request Failed”. These API’s are working fine on POSTMAN. If i replace this URL with url given in [https://facebook.github.io/react-native/docs/network.html], this code works.

componentDidMount(){ return fetch("https://api.kashu.com:4002/api/HomeData/1",{ method: 'GET', headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'x-ibm-client-id' : 'default', 'x-ibm-client-secret': 'SECRET' } }) .then((response) => response.json()) .then((responseJson) => { alert(responseJson); this.setState({ isLoading: false, dataSource: responseJson, }, function(){ }); }) .catch((error) =>{ console.error(error); }); }

Actual Response if API is run by POSTMAN or any client { "data": "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.", "id": 1 }

Environment

Environment: OS: Windows 10 Node: 8.10.0 Yarn: Not Found npm: 4.6.1 Watchman: Not Found Xcode: N/A Android Studio: Not Found Packages: (wanted => installed) react: 16.2.0 => 16.2.0 react-native: 0.52.0 => 0.52.0 Platform: Testing App on iPhone6 using Expo Client API : Loopback API’s hosted on same local system, changed hostname - api.kashu.com(pointed to 127.0.0.1)

Steps to Reproduce

  1. Tried to make GET Request to Local Loopback.js API from 0.54 version of React Native
  2. Threw Network Error.

Expected Behavior

  1. API should be working.

Actual Behavior

Tried to make GET Request to Local Loopback.js API from 0.54 version of React Native & React native threw Network Error. iOS 6(Expo Client) Error Information - whatsapp image 2018-03-18 at 6 30 01 am

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

6reactions
yoaquimcommented, Jun 17, 2018

I’m having this same issue (using the Expo app on an iPhone 7 Plus).

My fetch function works perfectly: I’ve used it many times before.

Everything works on Simulator on my MacBook Pro (didn’t even have to change to 127.0.0.1, worked with localhost), but get a:

[Unhandled promise rejection: TypeError: Network request failed]
- node_modules/react-native/node_modules/whatwg-fetch/fetch.js:441:29 in onerror
- node_modules/event-target-shim/lib/event-target.js:172:43 in dispatchEvent
- ... 8 more stack frames from framework internals

when trying to run on my iPhone.

Suggestions?

0reactions
paulmthiebauthcommented, Dec 10, 2018

@yoaquim did you ever solve your issue? Im using what I thought to be the proper IPv4 # instead of localhost but I still get network request errors

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native fetch() Network Request Failed - Stack Overflow
Show activity on this post. When I create a brand new project using react-native init (RN version 0.29. 1) and put a fetch...
Read more >
HTTP Fetch fails with "TypeError: Network request ... - GitHub
There are 83 issues opened and unanswered about network requests failing with this generic error. The main causes of the pain are: Not...
Read more >
Connect to API local error with 'fetch' - Expo SDK - Forums
I run the request in Postman and there is works. I don't know why show me this error. dgarro21 ...
Read more >
Networking - React Native
Many mobile apps need to load resources from a remote URL. You may want to make a POST request to a REST API,...
Read more >
Why React Native Android Fetch failing on access to localhost
I get error messages when I make a request with fetch api or axios on android emulator when i user localhost. I get...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found