在 android 电脑模拟器中获取 json 数据

get json data in android emualtor from pc

我有在我的电脑上运行的网络 API "localhost",我想使用这个 API 在 android 应用程序中接收一些 json 数据。当 asp nec core web API 和 nativescript android 应用程序都在我的电脑中时,如何在 android 模拟器中获取 json 数据?

名称 localhost 解析为地址 127.0.0.1。根据关于模拟器网络的 docs

Also note that the address 127.0.0.1 on your development machine corresponds to the emulator's own loopback interface. If you want to access services running on your development machine loopback interface (a.k.a. 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead.

现在,为了从模拟器访问服务器,地址应该是这样的:http://10.0.2.2:xxxx,其中xxxx代表端口号。