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.

Fetch not working on localhost (Tried IP too.)

See original GitHub issue

Is 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:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

0reactions
andymurakamicommented, Dec 26, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

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