Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] c# – Cannot connect to localhost API from android

Posted on November 11, 2022 By

Solution 1 :

non-conforming client (such as in a mobile app, or just a shell script invoking curl), can and usually will completely ignore CORS. My best guess is CORS is not the problem here. So you have to check that your app can connect to the API. just launch browser on your phone and copy paste the API Ednpoint URI and check if the get request was success.

Problem :

I am having trouble now connecting to my simple API from my Android application project. I have my web application running on localhost:5001, I am able to get responses using POSTMAN and via URL in browsers. But when I run my android application in debug mode I cannot get any response from the api call. I simply use a bog-standard button on the pre-built app template. I see the GET request being executed but I get no response and no error/break in debug. I have changed the localhost:5001 to 192.168.x.xxx:5001 (myip), using localhost gave a connection refused error. I have also added rule in firewall to allow TCP connections to all local ports.

Any help would be appreciated

Kind regards
simple API call code on button click

error

error using my ip, just loads forever

Cors policysettings added

Cors origin tag in web api

PUBLISHED EXE localhost server running

I have also tried disabling the router firewall, and using port forwarding for HTTPS Server to my IP address

Comments

Comment posted by Mofid.Moghimi

You need to handle Cors Origin on your web api application

Comment posted by 192.168.x.xxx:5001

Thank you for the quick response, I added cors via NuGet PowerShell, and added app.UseCors() and added [EnableCors(origins: “

READ  [FIXED] Change Push Notification background color on Android 12
Powered by Inline Related Posts

Comment posted by localhost:5001/api/Data?driverCode=1LINK

Hi thank you for reply, i hvae posted the error i recove when just using the emulator browser with URL

Comment posted by Paul

that works fine in postman, if i change the localhost to my IP address in the mobile browser then the browser just loads forever

Comment posted by Paul

I also cannot access from my physical phone browser same results as emulator 🙁

Comment posted by Paul

And I also do believe this could be network related, is there anymore configuration I could check? Could it be relates to my ISP or router? I use plusnet for example

Comment posted by Paul

One more thing im reading, does my server need to be uploaded to a hosting site for this to work? im currently running the server on my PC via published debug exe (pictured), im also connected to the wifi via an internet booster as my router is to far from my room?

Android Tags:android, api, c#

Post navigation

Previous Post: [FIXED] java – is permission needed when choosing image from gallery on android?
Next Post: [FIXED] Android Java: How to get component in a custom view? (Trying to access components via findByViewId and get null)

Related Posts

[FIXED] xml – Center path of android vector Android
[FIXED] Android – Error while trying to login with Facebook SDK Android
[FIXED] java – How to make my fragment fit between my toolbar and bottom navigation bar and still make it scrollable? Android
[FIXED] How to reduce selected comment distance from code in Android Studio Android
[FIXED] Disable scrollview on Android tv Android
[FIXED] android – Flutter: Why is this class not recognized as a class? Android

Archives

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

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is a good substitute for condensed milk?
  • ¿Como el cuerpo te avisa cuando te va a dar un infarto?
  • What is the luxury brand of Jaguar?
  • Who is Big poppa baseball player?
  • What material are foam runners?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme