Fetch not working on localhost (Tried IP too.)
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment: OS: Windows 10 Node: 9.4.0 Yarn: 1.3.2 npm: 5.6.0 Android Studio: 3.0.1
Packages: (wanted => installed) react-native: 0.52.0 react: 16.2.0
Target Platform: Android 26
Issue Statement
API from local server doesnt’t seems to be working, i have tried localhost:3000, 10.0.2.2:3000, <LOCAL_IP>:3000 & 10.0.3.2:3000 In Android Getting network request failed error. Below is the code snippets im using for network request.
Note: I already added the Android Internet permission.
return fetch('http://192.168.3.148:3000/extension/auth')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
sem: responseJson
});
})
.catch((error) => {
console.error(error);
});
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
React Native Android Fetch failing on connection to local API
Open Dev Settings , then tap Debug server host & port for device . Here you can enter your machine's local IP with...
Read more >Localhost Refused to Connect Error: 5 Confirmed Ways to Fix It
Localhost refused to connect error can be caused by an incorrectly configured port, insufficient permissions, or an inoperative web server.
Read more >React Native fetch only working with localhost and NOT IP ...
So my iOS Simulator could hit my Rails app, but not my React Native app using the IP Address. Again, everything worked fine...
Read more >Localhost Refused to Connect - How to Fix the Error
When developing locally the localhost refused to connect is the worst error you can get. See the causes and what solves the error....
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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@srijishks You should try this solution: https://stackoverflow.com/questions/49206456/react-native-android-connect-backend-service-at-localhost
To me is not working:
fetch(‘https://facebook.github.io/react-native/movies.json’) .then((response) => response.json()) .then((responseJson) => { //Alert.alert(“my json” + responseJson.movies); AlertIOS.alert( “Get response”, "Movies query-> " +JSON.stringify(responseJson.movies) ) }) .catch((error) => { console.error(error); });
Returns Request Network Failed
If I use a IP example: http://200.98.245.39 this returns text of html ok.