Android Emulator loopback to IIS Express does not work, but does work with Cassini

后端 未结 4 1479
挽巷
挽巷 2020-12-01 18:30

I am attempting to post data from an Android application running in the Android Emulator on my local machine to a web application running under IIS Express also running on m

相关标签:
4条回答
  • 2020-12-01 18:57

    Grant yourself permission to bind to network adapters other than localhost, and configure IIS express to bind to all adapters.

    IIS Express will then accept connections from the Android emulator via 10.0.2.2. If you add a rule to the firewall, you can also expose IIS Express to your network, which decreases security but is useful for testing physical devices.

    Step details: (they assume a port number of 5555 - use your actual port instead)

    1. Run this from a command prompt as Administrator:

      netsh http add urlacl url=http://*:5555/ user="NT AUTHORITY\INTERACTIVE"

    2. In %USERPROFILE%\Documents\IISExpress\config\applicationhost.config, replace your site's localhost binding with bindingInformation="*:5555:*". The result should look like this:

        <site name="..." id="...">
            <!-- application settings omitted for brevity -->
            <bindings>
                <binding protocol="http" bindingInformation="*:5555:*" />
            </bindings>
        </site>
    
    0 讨论(0)
  • 2020-12-01 19:00

    By default, IIS Express only accepts connections from localhost. To enable connections from remote devices (and the emulator counts as such), use the instructions from here.

    In short:

    netsh http add urlacl url=http://[machinename]:[port]/ user=everyone
    netsh http delete urlacl url=http://[machinename]:[port]/
    

    Replace [machinename] and [port] with your computer name (or non-local IP) and port IIS Express runs on.

    Also, see this question and this one.

    0 讨论(0)
  • 2020-12-01 19:06

    Here is my solution: I am using Visual Studio Express 2013 for Web and my RESTful web service is running on IIS express. When I tried to access my web service using an Android emulator in the same machine it gave me this invalid hostname error. As suggested by above answers I did add new bindings to my applicationhost.config file but still it didn't work. At last, I was able to fix this issue by running Visual Studio "as administrator".

    0 讨论(0)
  • 2020-12-01 19:23

    Add following line to IIs config file (ex c:\Users[YourName]\Documents\IISExpress\config\applicationhost.config ) Change the port 8085 if required..

    <binding protocol="http" bindingInformation="*:8085:127.0.0.1" />
    

    so your config file will end-up with something like this

    <bindings>
    <binding protocol="http" bindingInformation="*:4396:localhost" />     // the existing one
    <binding protocol="http" bindingInformation="*:8085:127.0.0.1" />     // new line
    </bindings>
    

    now you can call your web service from remote by calling to port 8085

    ex from android emu.
    new HttpPost("http://10.0.2.2:8085");
    
    0 讨论(0)
提交回复
热议问题