Local Fetch GET Network Request Failing
See original GitHub issueDescription 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
- Tried to make GET Request to Local Loopback.js API from 0.54 version of React Native
- Threw Network Error.
Expected Behavior
- 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 -
- I have reviewed the documentation
- I have searched existing issues
- I am using the latest React Native version
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
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 withlocalhost
), but get a:when trying to run on my iPhone.
Suggestions?
@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