当请求重定向到表单时到达服务器

发布于 2024-11-19 14:36:44 字数 192 浏览 2 评论 0原文

当必须在授予互联网访问权限之前填写浏览器表单时,我遇到了 wifi 连接问题。用户(如果使用浏览器)将被重定向到登录表单,要求他们登录或注册 wifi 访问。 用户没有使用浏览器,但从我的应用程序到服务器的请求被重定向到登录表单,从而导致服务器无法访问。是否有一种优雅的方法来检测这种行为并至少警告用户该问题。 在许多情况下,移动网络可用,只需关闭 wifi 即可。

I have an issue with wifi connectivity when a browser form must be completed before internet access is granted. The user (if using a browser) is redirected to a login form requiring them to login or sign up for wifi access.
The users are not using a browser but a request from my app to the server is redirected to a login form making the server unreachable. Is there a graceful way of detecting this behaviour and at least warning the user of the issue..
In many cases the mobile network is available and switching off wifi is all that is required.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

念三年u 2024-11-26 14:36:44

HTTP 重定向具有特定的响应代码(嗯,有几个特定的​​响应代码,从 300 到 307)。您可以在假设您有连接之前读取响应代码并从该点处理故障。

重定向的响应标头中还应该有一个 Location 值,因此您可以捕获该值并启动 WebView,将 Location 作为 URL 传递,从而使用户可以访问登录表单。不过,这会变得有点复杂,具体取决于会话的验证方式 - 例如,如果有 cookie,您必须从表单响应中提取它并存储它以供将来来自本机代码的请求。这些会话通常使用 MAC 地址,在这种情况下,您无需执行任何其他操作(除了处理成功登录并再次尝试您的请求之外)。

我希望这有帮助。

An HTTP redirect has a specific response code (well, several specific response codes, from 300 to 307). You could read the responseCode before assuming that you have a connection and handle the failure from that point.

A redirect should also have a Location value in the response header, so you could conceiveably capture that value and launch a WebView, passing Location as the URL, giving the user access to the login form. This would get a little complex, though, depending on how the session is validated - if there's a cookie, for instance, you'd have to extract it from the form response and store it for future requests from your native code. Often these sessions employ the MAC address, in which case you wouldn't have to do anything else (apart from handle a successful login and try your request again).

I hope that's helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文