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 for HTTP requests on Android

See original GitHub issue

🐛 Bug Report

When using fetch on http endpoints, the request raises a Network Request Fail error. If works fine on https endpoints.

To Reproduce

use fetch with any http url.

Expected Behavior

The fetch function returns without throwing a Network Request Fail

Code Example

fetch(any-http-url)

Environment

  React Native Environment Info:
    System:
      OS: Linux 4.15 KDE neon 5.14
    Binaries:
      Node: 10.6.0 - /usr/local/bin/node
      Yarn: 1.12.3 - /usr/bin/yarn
      npm: 6.1.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      Android SDK:
        API Levels: 23, 25, 26, 27, 28
        Build Tools: 23.0.1, 23.0.3, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 27.0.3, 28.0.1, 28.0.3
        System Images: android-27 | Google Play Intel x86 Atom
    npmPackages:
      react: 16.8.6 => 16.8.6 
      react-native: 0.59.2 => 0.59.2 
    npmGlobalPackages:
      create-react-native-app: 2.0.2
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22

github_iconTop GitHub Comments

76reactions
alexPimentelcommented, May 8, 2019

Try using this one. It worked for me.

Add the codes in your main AndroidManifest.xml :

<manifest 
  xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />

    <application
      android:usesCleartextTraffic="true" tools:targetApi="28"> 
    ... 
    </application>
</manifest>
25reactions
karanpratapsinghcommented, Apr 11, 2019

Hey, I’ve had a similar problem, please make sure your request URL is HTTPS not HTTP as Android from new versions doesn’t allow HTTP

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native Http request dont work in Android - Stack Overflow
Show activity on this post. this is the request code: fetch(URL,{ method: 'POST', headers: { Accept: 'application/json', 'Content-Type': ' ...
Read more >
fetch() - Web APIs | MDN
The global fetch() method starts the process of fetching a resource from the network, returning a promise which is fulfilled once the response...
Read more >
Http request not working in android pie, Allow http request from ...
Http request not working in android pie; Allow http request from android; React-native fetch not working on android; Android api level 28; App...
Read more >
Cannot make any network request (fetch) in react-native 0.63 ...
As you can see it's pretty simple but it's not working, if I check the network tab no XHR requests at all, no...
Read more >
React Native Fetch - To make HTTP API call in ... - About React
Code Snippet of Basic Network Call using Fetch ... fetch('Web URL HERE', { method: 'GET' //Request Type }) .then((response) => response.json()) //If response...
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