Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] Android Fetch API not working on app/REST client but working through browser

Posted on November 14, 2022

Solution 1 :

You need to be on the same wifi-network on both laptop and mobile. Plus the IP should be same as of laptop’s.

Solution 2 :

If you are not using SSL, you will have to enable Clear Text Traffic on your Manifest file:

<application
    ...
    android_usesCleartextTraffic="true">
    
    

Problem :

I am running several services on my local laptop which uses a range of ports. Everything is working when i’m using my android emulator on the laptop and i decided to test it using a real android device.

I’ve rooted the device and updated its host file to have the server url (used when during fetch calls) to point to my laptop’s ip address, similar to what i’ve done on my android emulator. I am able to hit the endpoints through my browser but it doesn’t work on my app (Network request fail). As such, I tried to hit the endpoints using a REST tester on android (RestClient) but it timeout-ed. I am using HTTP requests so far, so the SSL verification shouldn’t be a problem here.

I am also doubting that the timeout is due to speed issue since the wifi speed of my devices isn’t too bad?

I am confused as to why my browser on the Android device is hitting the endpoint but my app isn’t able to? When using postman/emulator on my local computer (where the services are hosted), everything is working fine too.

Any help will be appreciated, thank you!

Some other info about my Android device:

  • Galaxy Note 5, Android Version 7.0 & rooted

Comments

Comment posted by Rohan Pawar

have you added internet permission in manifest?. please your https request code

READ  [ANSWERED] android - Reverse Animation With Recursive Function
Powered by Inline Related Posts

Comment posted by kito

@RohanPawar yep i have it! This line is inside my manifest:

Comment posted by kito

@RohanPawar i’m actually fetching a HTTP url, which works on my local computer’s browser,postman & emulator as well as my android device’s browser so i have a feeling the fetch method and url is not the issue?

Comment posted by kito

hello, thanks for the reply! I made sure that they are in the same wifi-network! I am not sure what you mean by the IP should be same as the laptop’s. What i’ve done is edit the /system/etc/hosts file to point to that ip address for the url used in the fetch call. As such, i can hit the endpoints on the browser of my phone, but weirdly not on the Rest Client app.

Comment posted by kito

hey there, thanks for the reply! I’ve already included this but it wasn’t working 🙁

Comment posted by Helton Malambane

@kito If you can reach the endpoint on the phone’s browser means your network connection is ok. Can you please post your error stacktrace? Maybe there could be a problem with the returned content-type and it fails to parse.

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress