简体   繁体   中英

Cannot connect to localhost API from android

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM