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 Request not working on android, but working on IOS #30827

Closed
DylanRiden opened this issue Feb 1, 2021 · 13 comments
Closed

Fetch Request not working on android, but working on IOS #30827

DylanRiden opened this issue Feb 1, 2021 · 13 comments
Labels
Needs: Triage 🔍 p: Expo Partner: Expo Partner Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@DylanRiden
Copy link

Description

Hi, I have been developing with react native for awhile with Ios, but when it came to testing on android I get a "TypeError: Network request failed "error when trying to connect to my API, other APIs work but I just can't get mine to work, I raised an issue with expo and they couldn't figure it out and said it was probably an upstream react-native issue.

They thought it may be down to an Alt-Svc header

See expo/expo#11679 for original issue

Thanks In Advance :)

React Native version:

Expo SDK 40

Steps To Reproduce

  1. Run this https://snack.expo.io/@dylander/7cfe32 on android
  2. The request is inside AssetExample to my API that is failing
  3. If you type the url to my API you will see the expected response

Expected Results

The request response would outputted in the console, the catch runs and the error is outputted as an alert

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

In steps to reproduce

@ApayRus
Copy link

ApayRus commented Feb 5, 2021

I faced the same issue. On web i handled it with installing 'cors' extension -- now it works on web.
But on android expo client I even doesn't see any error, though I use try/catch. I tried with promise, with async await, with fetch and axios. Nothing is working :(

@DylanRiden
Copy link
Author

Hmm, the person trying in the other issue thought it could be to do with the "Alt-Svc" header, do you think it could be due to this??

@ApayRus
Copy link

ApayRus commented Feb 5, 2021

Hmm, the person trying in the other issue thought it could be to do with the "Alt-Svc" header, do you think it could be due to this??

I don't know what to set for 'alt-svc'? I found one example 'alt-svc':''http/1.1= "http2.example.com:8001"; ma=7200' and tried it, but it doesn't help me.

I have added to my api some headers, like

("Access-Control-Allow-Origin: *");
("Access-Control-Allow-Methods: GET");
("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

And now fetch works in web without any chrome extensions for 'cors'.

@DylanRiden
Copy link
Author

How do you host your api?? From your local network or a provider ?

@ApayRus
Copy link

ApayRus commented Feb 7, 2021

How do you host your api?? From your local network or a provider ?

both. I have next.js server, on local for dev, and on vercel for production. They both are working well from expo web emulator (also in poster). But doesn't work on expo android client (even without any error message, while I use try{}catch(err){}. I also tried github public api. The same behavior.

@SohaibKtb
Copy link

this is happening for me also when calling https request, the cert is form goddady and my server is hosted on digital ocean cloud.

react-native: 0.63.4

@sc-mudsat
Copy link

Hi, any luck?
Facing the same issue, the app working fine on IOS but fetch fails in android giving "[TypeError: Network request failed]" error.

@ApayRus
Copy link

ApayRus commented Oct 15, 2021

Hi, any luck? Facing the same issue, the app working fine on IOS but fetch fails in android giving "[TypeError: Network request failed]" error.

I didn't remember exactly what I did to solve, :) I suggest it was different headers of client request, and server response.
Also I had some link at resource, that used something like geo position, and there was an error from different clients because of their settings.

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment 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 Oct 31, 2023
Copy link

github-actions bot commented Nov 7, 2023

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as completed Nov 7, 2023
@ibraispotato
Copy link

i got the same issus did anyone got it?

@Tinkerstem
Copy link

Same issue here. Surprisingly it works on web perfectly, but not on mobile devices. Any success?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 p: Expo Partner: Expo Partner 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