gpt4 book ai didi

Android Webview - 重定向时给出 'Object moved to'

转载 作者:行者123 更新时间:2023-11-29 14:02:11 27 4
gpt4 key购买 nike

我在我的 Android 应用程序中包含了一个 WebView 连接到信用卡验证服务。表单加载正确,如果我输入错误的值,我会收到预期的错误。但是,对于正确的值,服务会重定向到另一个页面,该页面应显示成功的验证消息。相反,我只收到“对象移至此处”消息。当我点击“这里”时,它就变成空白了。我尝试如下重载 WebViewClient,认为重定向可能无法正确处理,但这似乎没有帮助。

WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.loadUrl("http://username:password@address...");
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.e("WebViewLog",url);
view.loadUrl(url);

return true;
}
});

我该怎么做才能解决这个问题?

我应该补充一点,该 URL 具有基本身份验证。我在 URL 中传递此信息是 mWebView.loadUrl("http://username:password@address...")

LogCat如下:

01-21 23:02:12.167: D/dalvikvm(3974): GC_CONCURRENT freed 1240K, 58% free 3061K/7175K, external 3160K/3465K, paused 1ms+2ms
01-21 23:02:17.867: D/navcache(3974): cursorInputFieldAction : No node under current cursor
01-21 23:02:17.867: D/navcache(3974): cursorInputFieldAction cursor=50e014, cursorFrame=50d828
01-21 23:02:17.867: D/navcache(3974): CachedFrame::previousInputField this=50d828, start=50e014, begin=50dfb0 end=50e208
01-21 23:02:17.867: D/navcache(3974): CachedFrame::nextInputField this=50d828, start=50e014, begin=50dfb0 end=50e208
01-21 23:02:17.867: D/navcache(3974): cursorInputFieldAction next=50e140, prev=0, action=8
01-21 23:02:17.999: V/webview(3974): OnSizeChanged: Enter
01-21 23:02:17.999: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:20.335: W/KeyCharacterMap(3974): No keyboard for id 0
01-21 23:02:20.335: W/KeyCharacterMap(3974): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
01-21 23:02:20.363: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:20.878: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:21.320: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:22.164: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:22.855: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:23.183: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:23.492: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:23.769: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:24.531: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:24.874: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:25.187: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:25.507: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:27.210: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:27.546: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:27.812: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:28.117: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:37.542: D/navcache(3974): cursorInputFieldAction cursor=4bd634, cursorFrame=4f3160
01-21 23:02:37.542: D/navcache(3974): CachedFrame::previousInputField this=4f3160, start=4bd634, begin=4bd5d0 end=4bd828
01-21 23:02:37.542: D/navcache(3974): CachedFrame::nextInputField this=4f3160, start=4bd634, begin=4bd5d0 end=4bd828
01-21 23:02:37.542: D/navcache(3974): cursorInputFieldAction next=4bd760, prev=0, action=8
01-21 23:02:37.632: E/webtextview(3974): ....Doing a super.requestRectangleOnScreen....
01-21 23:02:37.648: V/webview(3974): OnSizeChanged: Enter
01-21 23:02:38.847: D/navcache(3974): cursorInputFieldAction cursor=507fd0, cursorFrame=4f3160
01-21 23:02:38.847: D/navcache(3974): CachedFrame::previousInputField this=4f3160, start=507fd0, begin=507e40 end=508098
01-21 23:02:38.847: D/navcache(3974): CachedFrame::nextInputField this=4f3160, start=507fd0, begin=507e40 end=508098
01-21 23:02:38.847: D/navcache(3974): cursorInputFieldAction next=508034, prev=507ea4, action=9
01-21 23:02:39.070: D/dalvikvm(3974): GC_CONCURRENT freed 1098K, 57% free 3087K/7175K, external 3171K/3465K, paused 2ms+2ms
01-21 23:02:39.109: V/webview(3974): OnSizeChanged: Enter
01-21 23:02:39.164: V/webview(3974): Select Control Rect(101, 210 - 161, 241)
01-21 23:02:41.261: V/webview(3974): OnSizeChanged: Enter
01-21 23:02:42.656: D/navcache(3974): cursorInputFieldAction cursor=507ff4, cursorFrame=4cb1d0
01-21 23:02:42.656: D/navcache(3974): CachedFrame::previousInputField this=4cb1d0, start=507ff4, begin=507e00 end=508058
01-21 23:02:42.656: D/navcache(3974): CachedFrame::nextInputField this=4cb1d0, start=507ff4, begin=507e00 end=508058
01-21 23:02:42.656: D/navcache(3974): cursorInputFieldAction next=0, prev=507f90, action=18
01-21 23:02:42.847: V/webview(3974): OnSizeChanged: Enter
01-21 23:02:42.902: V/webview(3974): Select Control Rect(165, 210 - 242, 241)
01-21 23:02:45.308: V/webview(3974): OnSizeChanged: Enter
01-21 23:03:12.296: D/dalvikvm(3974): GC_CONCURRENT freed 1166K, 57% free 3129K/7175K, external 3171K/3465K, paused 9ms+3ms
01-21 23:03:12.304: D/webviewglue(3974): nativeDestroy view: 0x449480

每次单击某些内容时,我都会收到 Doing a super.requestRectangleOnScreen 错误。否则,我放入 WebViewClient 代码中的 Log.e 甚至不会显示。

更新:我在 Android 浏览器(在 Galaxy Tab 上)上进行了同样的操作。完全没有问题,但我注意到这里的差异以供引用。我收到用户名和密码提示,因为我使用了直接链接,但我也收到了证书异常,我接受了,因为这是用于测试的 BETA。此外,Android 浏览器同时使用 http://https://WebView 甚至不显示第一页我将 https:// 与 URL 一起使用。

最佳答案

public boolean shouldOverrideUrlLoading (WebView view, String url) Since: API Level 1

Give the host application a chance to take over the control when a new url is about to be loaded in the current WebView. If WebViewClient is not provided, by default WebView will ask Activity Manager to choose the proper handler for the url. If WebViewClient is provided, return true means the host application handles the url, while return false means the current WebView handles the url.

这总是让我感到困惑,但要解释一下......

当一个新的url即将被加载时,这个方法被调用。如果您返回 true,则主机应用程序将处理该 url。换句话说,返回 true 告诉主机应用程序它应该覆盖 url 加载 - 这可能导致重定向或调用库存浏览器。据我所知,这不是您想要的。

您应该返回 false 以向主机应用程序显示您的 WebView 已处理它并且主机应用程序不应覆盖 url 加载。

关于Android Webview - 重定向时给出 'Object moved to',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952768/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com