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

[android] I can not query on a local server (localhost) with fetch library, error "Network request failed" #24872

Closed
davidgaspardev opened this issue May 15, 2019 · 1 comment
Labels
🌐Networking Related to a networking API. Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot. Type: Question Issues that are actually questions and not bug reports.

Comments

@davidgaspardev
Copy link

davidgaspardev commented May 15, 2019

React-Native Framework

I always get the same error and have nothing wrong on the server side, the problem is in the fetch method.

can anybody help me ?

My code (Api.js):

const API_URL     = 'https://10.0.0.9';
const API_PORT    = 3000;
const API_QUERY   = '?data=';
const API_ERR_ARG = { error: 'unsupported argument type' };

/**
 * HTTP Communication (API)
 */
async function getData(dataType, callback, callbackErr) {

  if(typeof(dataType) !== 'string') return API_ERR_ARG;

  try {

    // address: https://localhost:3000?data=argument
    const response = await fetch(`${API_URL}:${API_PORT}${API_QUERY}${dataType}`);
    const responseJson = await response.json();

    if(typeof(callback) === 'function') callback(responseJson);

  }catch(error) {

    // An error occurred while connecting
    console.log(error);
    if(typeof(callbackErr) === 'function') callbackErr(error);

  }

}

export { getData };
@davidgaspardev davidgaspardev added the Type: Question Issues that are actually questions and not bug reports. label May 15, 2019
@davidgaspardev davidgaspardev changed the title Android | I can not query on a local server (localhost) with fetch library, error "Network request failed" [android] I can not query on a local server (localhost) with fetch library, error "Network request failed" May 15, 2019
@react-native-bot react-native-bot added Platform: Android Android applications. 🌐Networking Related to a networking API. labels May 15, 2019
@react-native-bot
Copy link
Collaborator

We are automatically closing this issue because it does not appear to follow any of the provided issue templates.

👉 Click here if you want to report a reproducible bug or regression in React Native.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Resolution: No Template labels May 15, 2019
@facebook facebook locked as resolved and limited conversation to collaborators May 15, 2020
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label May 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🌐Networking Related to a networking API. Platform: Android Android applications. Ran Commands One of our bots successfully processed a command. Resolution: Locked This issue was locked by the bot. Type: Question Issues that are actually questions and not bug reports.
Projects
None yet
Development

No branches or pull requests

2 participants