Android 模拟器未连接到 localhost api [英] Android emulator not connecting to localhost api
问题描述
我有一个 Xamarin 应用程序和本地主机 API.我正在尝试从应用程序连接到 API,但找不到它.我编辑了我的 applicationhost.config
文件,并在通话中尝试了 localhost
、10.0.2.2
和我的 IP 地址,但它不起作用.
那么,如何配置简单的 API 访问权限?(API 本身运行良好)
有一个简单的解决方法来连接 Emulator &我正在使用的本地主机 API 模拟器.
使用前缀打开您的服务 URL(从浏览器中获取):ngrok http --host-header=rewrite
现在转到执行服务的浏览器,打开另一个选项卡 &输入 localhost:4040 然后按 Enter -->转到状态,您将找到可以在移动应用程序中使用的公共 URL.
注意:Url 结构应该是这样的 public const string BaseUri = "https://8c56892f.ngrok.io/";
后跟 /
最后.尽量不要在命令提示符中附加不必要的/,
优点
通过使用这种方法,您可以将服务从一个 Visual Studio 调试到另一个.
您的 URL 将一直处于活动状态,直到您关闭命令提示符.
在浏览器或命令提示符下跟踪您的请求状态,例如确定、未找到等
有关更多信息,请访问此https://www.c-sharpcorner.com/article/exposing-local-web-server-to-internet-using-ngrok/
希望对你有帮助.
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)
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
Open your service URL(take from your browser) with prefix: ngrok http --host-header=rewrite
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.
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
By using this method you can debug services from one Visual Studio to another.
Your URL will be active until you close command prompt.
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.
这篇关于Android 模拟器未连接到 localhost api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!