Android Volley库不适用于本地IP [英] android volley library does not work on local IP

查看:76
本文介绍了Android Volley库不适用于本地IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我想从本地网络上的系统中获取数据时,volley无法正常工作. URL类似于http://192.168.x.x/data.php 它可以在仿真器上很好地工作,但不能在真实的设备上工作.它显示了我们的错误时间. 即使我尝试设置最大时间我们的重试策略.但徒劳.

解决方案

有两种解决方法:

a)保持设备连接到使用lan或wifi连接到本地网络的PC.保持调试模式打开.使用ipconfig来检查您的PC的ipv4地址并使用它.

在路由器上转发服务器的端口,然后使用PC的ipconfig命令中找到的ipv4地址.

c)最好的选择->我用这个.在路由器上转发您的计算机的服务器端口,转到路由器的DHCP配置,并为您的计算机mac提供一个首选的DHCP IP,以确保您的路由器始终将本地IP赋予您的计算机(如果您没有静态IP,全局将仍然是动态的).注册到DDNS并使用上面的设置ip,您将可以在世界任何地方访问您的Web服务. (我在ddns部分使用dynudns)

请参见>如何从我的主机访问我的本地主机Android设备?还有其他想法

在前两个步骤中,请确保移动设备通过wifi连接,以便路由器可以转发它的请求.第三,它可以按照自己喜欢的方式连接到互联网.同样在第一个中,您每次本地IP更改时都必须更改URL.

在第二个选项中,DNS将提供一个用于自动ip更新的工具:)

volley is not working when i want to fetch data from a system on my local network. where URL is like http://192.168.x.x/data.php it works well on emulator but not on a real device. it show a time our error. even i tried setting a maximum time our and retry policy. but in vain.

解决方案

There are two ways to solve this:

a) keep your device connected to the PC which is connected to your local network either using lan or wifi. Keep debugging mode on. Use ipconfig to check your pcs ipv4 address and use that.

forward your server's port on your router and then use the ipv4 address found on your pc's ipconfig command.

c) Best option-> i use this. Forward your pc's server port on your router, Go to your router's DHCP configurations and give your pc mac a preferred DHCP ip to make sure your router always gives that local ip to your pc(global will still be dynamic if you dont have a static ip). Register to a DDNS and use the set ip above and you will be able to access your web service from anywhere in the world. (i use dynudns for the ddns part)

see How can I access my localhost from my Android device? for other ideas

In the first two steps, make sure that the mobile is connected via wifi so that the router can forward it requests. in third, it can be connected to the internet anyway it likes. Also in the first, you will have to change the url everytime your local ip changes.

In second option, the dns will give a tool for auto ip updation :)

这篇关于Android Volley库不适用于本地IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆