Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
583 views
in Technique[技术] by (71.8m points)

c# - Android emulator not connecting to localhost api

I have a Xamarin app and localhost API. I'm trying to connect to the API from the app, but it could not be found. I edited my applicationhost.config file and I tried localhost, 10.0.2.2 and my IP address in the call, but it was not working.

So, how do I configure simple API access? (The API itself is working well)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is a simple workaround to connect Emulator & Simulator to localhost API's which I am using.

Download third party software NgRok for Windows at any specific location of your PC. It just contains one executable file called ngrok.exe. Now execute your service on your preferred browser. Than follow below steps.

  • Open your ngrok location on command prompt

    enter image description here

  • Open your service URL(take from your browser) with prefix: ngrok http --host-header=rewrite

    enter image description here

  • Now go to your browser where you have execute your service open another tab & type localhost:4040 than press enter -->Go to status there you will find your public URL which you can use in your mobile application.

    enter image description here

Note: Url structure should be like this public const string BaseUri = "https://8c56892f.ngrok.io/"; followed by / in last. Try not to append unnecessary /, in command prompt.

Benifits

  1. By using this method you can debug services from one Visual Studio to another.

  2. Your URL will be active until you close command prompt.

  3. In browser or command prompt track your requests status like Ok, not found etc.

For more information visit this https://www.c-sharpcorner.com/article/exposing-local-web-server-to-internet-using-ngrok/

Hope it help you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...