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 failures on Android #29782

Closed
ambarc opened this issue Aug 26, 2020 · 12 comments
Closed

Fetch failures on Android #29782

ambarc opened this issue Aug 26, 2020 · 12 comments
Labels
Needs: Author Feedback 🌐Networking Related to a networking API. Newer Patch Available Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@ambarc
Copy link

ambarc commented Aug 26, 2020

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

Fetch POST and PUT requests, to https endpoints, fail with "Network request failed", on android simulator. We're observing this after upgrading from 0.59.10 to 0.61.5. We can't upgrade further (yet) given other dependencies breaking.

Observation: Adding a Header object to these requests, as opposed to empty, or JS' empty object {}, leads to different behavior. All these requests work as-is on iOS. See simplified code samples.

React Native version: 0.61.5

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

// works on 0.59.10. doesn't work on 0.61.5
fetch('target-url', {
    method: 'POST'
    headers: { h1: 'val1' } // fails where it used to succeed. Network Request Failed.
})

let h =  new Headers()
h.set('h1', 'val1')
fetch('target-url', {
    method: 'POST'
    headers: h // strangely succeeds.
})

Expected Results

Expect prior requests from 0.59.10, as described above, to work across iOS and Android.

Snack, code example, screenshot, or link to a repository:

See above.

@therealansh
Copy link

Are you using a localhost api? If so try changing the target url to http://10.0.2.2 for android emulator and if you are trying it on a real device try changing the endpoints to your computer's local IP address. But it is strange that it used to work before v0.61.5

@ambarc
Copy link
Author

ambarc commented Aug 28, 2020

Ty! No, this is for a hosted API, not on local, using https.

@github-actions
Copy link

⚠️ Using Old Version
ℹ️ It looks like you are using an older version of React Native. Please upgrade to the latest version, and verify if the issue persists. If it does not, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the current release.

@safaiyeh
Copy link
Contributor

Hi @ambarc thanks for the issue! Is it similar to this? #29608

@ambarc
Copy link
Author

ambarc commented Aug 29, 2020

It's very similar, but I think that issue might be running into broader problems. I'm trying to keep this issue open and focused on the presence of Headers being the difference between pass / fail on Android.

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Aug 29, 2020
@safaiyeh
Copy link
Contributor

Hi @ambarc looks like the issue I linked is closed and the author provided a bunch of details to resolve it. Could you give that a shot?

@safaiyeh safaiyeh added Needs: Author Feedback and removed Needs: Attention Issues where the author has responded to feedback. labels Oct 28, 2020
@brian-nicholls
Copy link

brian-nicholls commented Dec 13, 2020

Are you using a localhost api? If so try changing the target url to http://10.0.2.2 for android emulator and if you are trying it on a real device try changing the endpoints to your computer's local IP address. But it is strange that it used to work before v0.61.5

A similar solution worked for me. My local Rails API was running on 127.0.0.1:4001. I'm using Expo, which was running my app on 10.0.0.5:19000 (my Mac's local IP). I changed my API URL when starting the rails server using rails s -b 10.0.0.5 to match Expo.

It now works on my Android emulator and device.

@vTrip
Copy link

vTrip commented Dec 16, 2020

Hey @ambarc, leaving a comment to say thank you for sharing this, after many long hours and testing of different RN versions to try and narrow my problem, this has solved it for me.

My research has found that my issue showed up with the upgrade of android SDK versions specified in the android/gradle file. Going from 28 -> 29.

Modifying my HTTP service to create the headers via new Headers() as opposed to plain JS headers = {} which previously worked with no issues for outgoing POST requests solved it for me.

I am really curious to know if this is purely a type error and why RN / fetch API throws an error for this so strictly.

Anyway, thanks for sharing, very grateful.

@SohaibKtb
Copy link

+1

@flyskywhy
Copy link
Contributor

fixed TypeError: Network request failed when upload file to http not https with Android debug builds

@github-actions
Copy link

github-actions bot commented Apr 1, 2023

This issue is waiting for author's feedback since 24 days. Please provide the requested feedback or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 1, 2023
@github-actions
Copy link

github-actions bot commented Apr 8, 2023

This issue was closed because the author hasn't provided the requested feedback after 7 days.

@github-actions github-actions bot closed this as completed Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Author Feedback 🌐Networking Related to a networking API. Newer Patch Available Platform: Android Android applications. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

8 participants