Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch not working on localhost (Tried IP too.) #17758

Closed
fahidmohammad opened this issue Jan 27, 2018 · 8 comments
Closed

Fetch not working on localhost (Tried IP too.) #17758

fahidmohammad opened this issue Jan 27, 2018 · 8 comments
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.

Comments

@fahidmohammad
Copy link

fahidmohammad commented Jan 27, 2018

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);
        });
@fahidmohammad fahidmohammad changed the title Featch not working on localhost (Tried IP too.) Fetch not working on localhost (Tried IP too.) Jan 27, 2018
@saxenanickk
Copy link
Contributor

Try to use "proxy": "http://localhost:3000/" inside your package.json file.

@react-native-bot
Copy link
Collaborator

Thanks for posting this! It looks like you may not be using the latest version of React Native, v0.53.0, released on January 2018. Can you make sure this issue can still be reproduced in the latest version?

I am going to close this, but please feel free to open a new issue if you are able to confirm that this is still a problem in v0.53.0 or newer.

How to ContributeWhat to Expect from Maintainers

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Stale There has been a lack of activity on this issue and it may be closed soon. labels Feb 24, 2018
@stale stale bot removed the Stale There has been a lack of activity on this issue and it may be closed soon. label Feb 24, 2018
@salmanwaheed
Copy link

salmanwaheed commented Feb 24, 2018 via email

@woodenlim
Copy link

The bug is still there.. Im using the latest version of RN.. Tested on Android 7.0 and Android 8.0..
7 is not working but 8 yes..

@kalpeshjjethva
Copy link

It's 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);
});

@srijishks
Copy link

Works with the server not with the localhost

@saxenanickk
Copy link
Contributor

saxenanickk commented Dec 10, 2018

@srijishks You should try this solution: https://stackoverflow.com/questions/49206456/react-native-android-connect-backend-service-at-localhost

@andymurakami
Copy link

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.

@facebook facebook locked as resolved and limited conversation to collaborators Feb 24, 2019
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Feb 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

8 participants