Unable to access local Web API from Visual Studio 2015 WIndows 10 Phone Emulator

泪湿孤枕 提交于 2019-12-23 05:11:25

问题


I'm currently developing a UWP phone app which calls a Web API.

When using the Visual Studio 2015 (Update 3) mobile emulators, calls to the Web API work fine for emulator versions 10.0.10240.0 and 10.0.10586.0. However, for the latest emulator versions 10.0.14393.0 my API calls all fail.

The http address I'm using to access the Web API, which is running under IIS Express, is http://localhost:64210. Using the emulator's browser, I can access this URL in 10240/10586, but not 14393.

I've tried following the relevant suggestions in this article by Anthony Baker, and this MSDN article, (both of which relate to the Windows Phone 8 emulator) but neither has led to a resolution.

I also noted that in the Hyper-V Manager the network setting for the 14393 emulator have the additional Network Adapter "Microsoft Emulator NAT Switch", but my experiments with this indicate it is not causing the problem.

Can anyone suggest a possible solution to this problem?


回答1:


You can try changing "localhost" to "10.0.2.2".

Base on this, if you are calling a local host from an emulator, you need to call 10.0.2.2 rather than the original 127.0.0.1. This is because localhost refers to the localhost of the emulator.



来源:https://stackoverflow.com/questions/41016341/unable-to-access-local-web-api-from-visual-studio-2015-windows-10-phone-emulator

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