强制门户 API 支持
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
从 Android 11 Beta 版 2 开始,系统支持 RFC7710bis 中所述的一部分功能以及关联的强制门户 API。
该 API 为接入点提供了一种可靠的方法来将其自身标识为强制门户。此外,它还支持接入点向用户发布信息(如会话和信息中心信息)的新用例。
改进了强制门户检测
从 Android 5.0(API 级别 21)开始,Android 设备就已能够检测强制门户,并通知用户他们需要登录网络才能访问互联网。之前是通过对已知目标网站(如 connectivitycheck.gstatic.com
)进行明文 HTTP 探测来检测强制门户,如果探测收到 HTTP 重定向,设备就会假定相应的网络是强制门户。这种方法可能不可靠,因为没有标准的网址可供探测,并且强制门户网络可能会错误地允许或阻止(而不是重定向)此类探测。该 API 允许门户提供一个表明要求登录的正信号,以及要登录的网址。
Android 11 支持 DHCP 选项 114,如 RFC7710bis 中所述。我们可能会在未来的更新中添加对路由器通告选项的支持。如果设备在 DHCP 握手期间通过该选项获得强制门户 API 网址,设备会在连接后立即提取 API 内容,按照强制门户 API 要求,如果网络是强制门户,还会提示用户登录。
如果该 API 不可用或未通告任何门户,系统会像以前一样,继续使用 HTTP/HTTPS 探测来检测门户并验证互联网连接。
信息中心发布的信息
Android 11 支持强制门户 API 中定义的 venue-info-url
。此网址允许用户在其浏览器中获取有关接入点信息中心的特定于上下文的信息。默认情况下,如果用户选择打开此网址,可以在登录后从通知中打开,或从网络设置中打开。
图 1. 如果网络提供了信息中心网址,系统会弹出一条通知,允许用户访问该网页
图 2. 用于从“网络详情”屏幕中打开网站的按钮
未来的用例
虽然 Android 11 在发布时仅支持强制门户 API 中的一组基本功能,但在发布后可能会通过 Google Play 系统更新将新功能分发给设备。我们建议网络运营商实现强制门户 API,同时注意未来可能的改进:
- 会话时间 (
seconds-remaining
) 当前在默认的设置应用中用来告知用户在门户上还剩多长时间。通过登录网址延长会话的能力 (can-extend-session
) 也可以通过该 API 表示,以允许系统通知用户已到期或即将到期的会话。
- 数据上限 (
bytes-remaining
) 可以通过该 API 通告,以允许用户跟踪剩余数据。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-27。"],[],[],null,["Starting in Android 11 Beta 2, the system supports a subset of\nfunctionality described by\n[RFC7710bis](https://tools.ietf.org/html/draft-ietf-capport-rfc7710bis)\nand the associated [captive portal\nAPI](https://tools.ietf.org/html/draft-ietf-capport-api).\n\nThe API provides a reliable way for access points to identify themselves as\ncaptive portals. It also enables new use-cases for access points to publish\ninformation to their users, such as session and venue information.\n\nImproved captive portal detection\n\nSince Android 5.0 (API level 21), Android devices have detected captive portals\nand notified the user that they need to sign in to the network to access the\ninternet. Captive portals were detected using cleartext HTTP probes to known\ndestinations (such as `connectivitycheck.gstatic.com`), and if the probe\nreceived an HTTP redirect, the device assumed that the network was a captive\nportal. This technique can be unreliable because there is no standard URL to\nprobe, and such probes could be mistakenly allowed or blocked (instead of\nredirected) by captive portal networks. The API allows portals to provide a\npositive signal that login is required, along with a URL to log in to.\n\nAndroid 11 supports DHCP option 114 as described in RFC7710bis.\nWe may add support for the router advertisement option in a future update. If\nthe device gets a captive portal API URL through that option during the DHCP\nhandshake, devices fetch the API contents immediately after connecting and\nprompt users to log in if the network is captive, as per the captive portal API.\n\nIf the API is not available, or if no portal is advertised, the system will\ncontinue to detect portals and verify internet connectivity using HTTP/HTTPS\nprobes, as before.\n\nVenue-published information\n\nAndroid 11 supports the `venue-info-url` defined in the captive\nportal API. This URL allows users to obtain context-specific information about\nthe access point venue in their browser. By default, users can open this URL if\nthey choose to do so from a notification after logging in, or from their network\nsettings.\n\n\u003cbr /\u003e\n\n\n**Figure 1.** If the network provides a venue URL, the system pops up a notice\nallowing the user to visit that page\n\n\u003cbr /\u003e\n\n\n**Figure 2.** Button to open the site from the Network details screen\n\nFuture use cases\n\nWhile at launch Android 11 supports only a basic set of\nfunctionality from the captive portal API, new functionality may be delivered to\ndevices via Google Play system updates after launch. We encourage network\noperators to implement the captive portal API while keeping future possible\nimprovements in mind:\n\n- Session time (`seconds-remaining`) is currently used in the default **Settings** app to inform users on how much time is left on the portal. The ability to extend the session via the login URL (`can-extend-session`) can also be expressed through the API to allow the system to notify the user about expired or soon-to-expire sessions.\n- Data caps (`bytes-remaining`) can be advertised through the API to allow users to keep track of remaining data."]]