Connection to localhost on the Android emulator

佐手、 提交于 2021-02-10 06:25:14

问题


I can not connect to localhost in the android emulator.

The API I have built in Net Core 2 and running in VS2017 (Windows 10)

  • adress http://localhost:50069/api/values

What I checked and does not work (does not react):

  • http://10.0.2.2:50069/api/values
  • http://ip:50069/api/values (ip -> ipv4 address from ipconfig)
  • http://127.0.0.1:50069/api/values
  • http://0.0.0.0:50069/api/values

I've already checked out all the advice on what was on the net and nothing


回答1:


I had same problem with ASP.net. I fixed this problem by updating IP binding.

Note: Make sure to keep backup of your project before following steps.

In order to do that follow the below steps,

  1. Go to your project folder.
  2. Find and open .vs folder (by default it'll be hidden).
  3. Inside .vs folder open config folder.
  4. There you get applicationhost.config which contains your project related settings.
  5. Open it in Notepad, Notepad++ or any other favorite text editor.
  6. And find the following piece of code.

    <site name="YourAwesomeProject" id="2">
         <application path="/" applicationPool="Clr4IntegratedAppPool">
              <virtualDirectory path="/" physicalPath="/path/to/your/YourAwesomeProject" />
         </application>
         <bindings>
              <binding protocol="http" bindingInformation="*:50069:localhost" />
         </bindings>
    </site>
    
  7. Now you need to duplicate the following line and update it as I suggest here. Both lines are required do not remove the first line.

    <binding protocol="http" bindingInformation="*:50069:localhost" />
    <binding protocol="http" bindingInformation="*:50069:*" />  <!-- add an asterisk in place of localhost -->
    
  8. And restart the server.

    If it doesn't work even after updating file, turn off Windows Firewall or any Firewall service from Antivirus programs.

Now you can access API with your IP address.

http://<server_ip>:50069/api/values

Edit

Make sure that you're running Visual Studio with Administrative rights.



来源:https://stackoverflow.com/questions/51967712/connection-to-localhost-on-the-android-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!