Unable to access local Web API from Visual Studio

2019-06-14 02:49发布

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条回答
手持菜刀,她持情操
2楼-- · 2019-06-14 03:13

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.

查看更多
登录 后发表回答