Skip to content

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

Closed

Description

@davidgaspardev

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 };

Activity

  1. added
    Type: Question
    on May 15, 2019
  2. 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"[/+] on May 15, 2019
  3. added
    Platform: Android
    🌐Networking
    on May 15, 2019
  4. react-native-bot commented on May 15, 2019

    @react-native-bot
    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.

  5. added
    Ran Commands
    on May 15, 2019
  6. locked as resolved and limited conversation to collaborators on May 15, 2020
  7. added
    Resolution: Locked
    on May 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Platform: AndroidRan CommandsResolution: LockedType: Question🌐Networking

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions