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 Request fails on android only

See original GitHub issue

šŸ› Bug Report

I am not able to understand why my fetch request with multipart/formdata are failing for no apparent reason, the error just shows fetch request failed.

The strange part is the request completes on my backend like normal and my backend even send the response to the app till then the app has already failed to fetch.

Also, the same request completes the first time but failed after that. This works flawlessly on my ios devices.

Things I’ve already tried:

  • Content-Type header is present
  • Form data is correct (i’ve tripple checked)
  • request url is https
  • form data image field has type property

Code Example


let body = await jsonToFormDataParser(...blah blah form data);

let { newCard: updatedCard, success } = await fetch(`${serverUrl}/api/create/card`, {

            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'multipart/form-data',
            },
            body
        }).then(res => res.json());

Any help would be fantastic

Environment

React Native Environment Info: System: OS: macOS 10.14.3 CPU: (4) x64 IntelĀ® Coreā„¢ i5-5350U CPU @ 1.80GHz Memory: 183.94 MB / 8.00 GB Shell: 5.3 - /bin/zsh Binaries: Node: 11.10.0 - /usr/local/bin/node npm: 6.9.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1 Android SDK: API Levels: 23, 25, 26, 27, 28 Build Tools: 23.0.1, 23.0.3, 25.0.1, 25.0.2, 26.0.1, 26.0.2, 27.0.3, 28.0.2, 28.0.3 System Images: android-27 | Google APIs Intel x86 Atom, android-28 | Intel x86 Atom, android-28 | Intel x86 Atom_64, android-28 | Google APIs In tel x86 Atom IDEs: Android Studio: 3.3 AI-182.5107.16.33.5264788 Xcode: 10.1/10B61 - /usr/bin/xcodebuild npmPackages: react: 16.8.3 => 16.8.3 react-native: 0.59.3 => 0.59.3 npmGlobalPackages: create-react-native-app: 1.0.0 react-native-cli: 2.0.1

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
reddeguzmancommented, Nov 6, 2019
3reactions
legion-zvercommented, Apr 10, 2019

@karanpratapsingh i had a similar problem and the fault was the SSL certificates (backend). If You cannot replace certificates on the server, you can use pinning (or ready packages, for example react-native-ssl-pinning or manual set to OkClient + TrustKit)

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Only Android] fetch Error : [Network request failed] #33217
In react-native 0.63.2 (I'm testing) or some higher version, if just use fetch to upload file to a http (not https) server,Ā ...
Read more >
React Native fetch() Network Request Failed - Stack Overflow
1) To find out the exact error in the logs, I first enabled 'Debug JS Remotely' using Cmd + M on the app...
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 >
Networking - React Native
Many mobile apps need to load resources from a remote URL. You may want to make a POST request to a REST API,...
Read more >
How to solve 'TypeError: Network request failed' in React ...
two thing : 1. add android :usesCleartextTraffic="true" in your Android manifest android /app/src/main/AndroidManifest.xml2.
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