问题
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,
- Go to your project folder.
- Find and open
.vs
folder (by default it'll be hidden). - Inside
.vs
folder openconfig
folder. - There you get
applicationhost.config
which contains your project related settings. - Open it in Notepad, Notepad++ or any other favorite text editor.
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>
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 -->
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