Android模拟器未连接到localhost API [英] Android emulator not connecting to localhost api

查看:153
本文介绍了Android模拟器未连接到localhost API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xamarin应用程序和localhost API.我正在尝试从应用程序连接到API,但找不到它.我编辑了applicationhost.config文件,并在通话中尝试了localhost10.0.2.2和我的IP地址,但是它不起作用.

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.

那么,如何配置简单的API访问权限? (API本身运行良好)

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

推荐答案

有一个简单的解决方法来连接Emulator&模拟器到我正在使用的localhost API.

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

在PC的任何特定位置下载适用于Windows的第三方软件NgRok .它仅包含一个名为ngrok.exe的可执行文件. 现在,在您喜欢的浏览器上执行您的服务.比按照以下步骤进行操作.

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.

  • 在命令提示符下打开您的ngrok位置

  • Open your ngrok location on command prompt

打开服务URL(从浏览器获取),前缀为:ngrok http --host-header = rewrite

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

现在转到执行服务的浏览器,打开另一个标签&键入localhost:4040,然后按Enter键->进入状态,您将找到可以在移动应用程序中使用的公共URL.

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.

注意:URL结构应类似于此public const string BaseUri = "https://8c56892f.ngrok.io/";,最后是/.尝试不要在命令提示符后附加不必要的/.

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.

好处

  1. 通过使用这种方法,您可以将服务从一个Visual Studio调试到另一个.

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

在关闭命令提示符之前,您的URL将一直处于活动状态.

Your URL will be active until you close command prompt.

在浏览器或命令提示符中,跟踪您的请求状态,例如确定",未找到"等.

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

有关更多信息,请访问以下 https://www.c-sharpcorner.com/article/exposed-local-web-server-to-internet-using-ngrok/

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆