且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何查看WiFi是否通过网页登录?

更新时间:2022-05-15 01:36:59

在 Android 上:您可以实现自己的 RedirectHandler 然后在 HttpClient 访问不应重定向的网站.如果您被重定向,则此接入点可能是围墙花园(无法访问互联网,无需进一步步骤).在那之后,您不太可能以编程方式简单地为用户登录,因为用户可能在任何地方并且可能需要付费才能使用互联网:酒店、飞机、咖啡店.相反,***的做法是通过对话框通知用户他们需要执行额外的步骤才能使用他们当前连接的 Wi-Fi 接入点访问互联网,然后允许他们轻松地打开 Web 浏览器访问将触发重定向的网站,例如 www.google.com.我知道这个解决方案有效,因为我以前自己实现过.

On Android: You can implement your own RedirectHandler and then use it in an HttpClient to hit a website that should never be redirected. If you get redirected then this access point is likely a walled garden (no access to the internet, without further steps). After that you are unlikely to be able to simply log in for the user programmatically, since the user could be anywhere and may need to pay to use the internet: hotel, airplane, coffee shop. Instead the best course of action is to inform the user with a dialog that they will need to perform additional steps to reach the internet using the Wi-Fi access point they are currently connected to and then allow them to easily open the web browser to a website that will trigger the redirect such as www.google.com. I know this solution works because I've implemented it myself before.

在 iPhone 上,这可能没有必要,因为一旦用户连接到围墙花园 Wi-Fi 接入点并显示浏览器,iPhone 就会检测到这些接入点.如果用户无法连接到互联网,iPhone 会断开用户与 Wi-Fi 接入点的连接.

On iPhone this probably isn't necessary since the iPhone already detects walled garden Wi-Fi access points as soon as the user connects to them and shows the browser. If the user fails to connect to the internet the iPhone disconnects the user from the Wi-Fi access point.