通过IP地址获取本地主机网页
我有一个 android 项目,它从网络的 URL 提供 XML 数据。我想测试一下,但我没有网址。
因此,我在 ASP.NET 项目上创建了一个 XML 页面,并将 URL 放在 android 项目上。但本地主机 URL 不起作用。
如何在 Visual Studio 中创建一个项目,以便我可以在 Android 项目中提供 IP 地址。我经历了 这个关于 TCP 客户端的教程 但无法解决我的问题。 (我没有 IIS 服务器,所以请不要将其作为解决方案)
I have a android project which feeds XML data from URL from web. I want to test this but I don't own a web address.
Therefore I created a XML Page on ASP.NET project and put the URL on android project. But the localhost URL didn't work.
How can I create a project in Visual Studio such that I can give the IP Address in the Android Project. I went through this tutorial about TCP Client but cannot resolve a solution for my problem. (I don't have an IIS Server so please don't give it as a solution)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您通过 Wi-Fi 网络使用真实设备,则您的真实主机 IP 地址应该有效。如果您使用模拟器,则您的主机地址为 10.0.2.2(请参阅此处的文档)。
If you are using real device via Wi-Fi network, your real host IP address should work. If you're using emulator, then your host address is 10.0.2.2 (see documentation here).
本地主机通常解析为 127.0.0.1 并且仅为本地计算机保留。我假设您的机器有一个某种描述的网卡,因此会有一个 IP 地址。这可能是由您的路由器(ADSL/电缆/等)自动分配的,但它会有一个。如果您不确定它是什么(并且假设,因为您正在谈论 VS,所以您正在使用 PC 进行开发),则打开命令提示符并键入
您将获得网络设备列表,其中之一将是您的 NIC 。您还应该看到与其关联的 IP 地址。
最后要做的事情是确保您的 Windows 防火墙不会阻止对移动应用程序使用的端口的访问。之后应该一切都好。如果您有另一台 PC,请尝试使用它浏览 XML 托管页面。
Localhost usually resolves to 127.0.0.1 and is reserved for the local machine only. I assume that your machine has a networks card of some description and as such will have an IP address. This may be assigned automatically by your router (ADSL/Cable/Etc) but it will have one. If you are not sure what it is (and assuming, since you are talking about VS you are developing with a PC) then open a command prompt and type
You will then get back a list of network devices and one of them will be your NIC. You should also see the IP address associated with it.
The final thing to do is ensure that your windows firewall is not blocking access to the port(s) used by your mobile app. Should all be fine after that. If you have another PC then try browsing to the XML hosted page using that.