Android Webview - 给出“对象移动到”重定向时

发布于 2024-12-28 08:22:36 字数 5759 浏览 2 评论 0原文

我在我的 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 一起使用。

I've included a a WebView in my Android app that connects to a credit card verification service.
The form loads correctly and I get errors as expected if I put in the wrong values. However, for the correct values the service redirects to another page that should show the successful verification message. Instead, I only get an "Object moved to here" message. When I click the 'here' it just goes blank.
I tried overloading the WebViewClient as below thinking that the redirect may not be handling correctly but that doesn't seem to help.

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;
        }
});

What can I do to fix this ?

I should add that the URL's have basic authentication. I pass this information in the URL is mWebView.loadUrl("http://username:password@address...").

LogCat is as below:

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

I get the Doing a super.requestRectangleOnScreen error every time I click something. Otherwise, the Log.e that I put in the WebViewClient code doesn't even show.

Update: I did the same activity on the Android browser (on a Galaxy Tab). No problems at all but I'm noting the differences here for reference. I get a username and password prompt cause I use the direct link but I also get a certificate exception which I accept because this is a BETA for testing. Also, the Android browser works using both http:// and https:// but the WebView doesn't even show the first page is I use https:// with the URL.

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

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

发布评论

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

评论(3

最单纯的乌龟 2025-01-04 08:22:36

public boolean shouldOverrideUrlLoading(WebView 视图,字符串 url)自:API 级别 1

当新的 url 即将加载到当前 WebView 中时,让主机应用程序有机会接管控制权。如果未提供 WebViewClient,默认情况下 WebView 将要求 Activity Manager 为 url 选择正确的处理程序。 如果提供了 WebViewClient,则返回 true 表示主机应用程序处理该 url,返回 false 表示当前 WebView 处理该 url。

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

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

您应该返回 false 向主机应用程序表明您的 WebView 已处理它,并且主机应用程序不应覆盖 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.

This always confuses me but to explain...

When a new url is about to be loaded, this method is called. If you return true then the host application will handle the url. In other words, returning true tells the host application that it SHOULD override url loading - this can cause redirections or the stock browser to be invoked. This, as far as I can tell, is not what you want.

You should return false to show the host application that your WebView has handled it and that the host application SHOULD NOT override url loading.

清风疏影 2025-01-04 08:22:36

解决了。毕竟是认证。在尝试了 WebView 的所有身份验证方法后,我切换到了 SSL。

该证书导致了一个问题,我可以使用 WebViewClient 中的以下方法覆盖来绕过该问题。

@Override
public void onReceivedSslError(WebView view,
                SslErrorHandler handler, SslError error) {
Log.e("Error", "Received SSL error"+ error.toString());
handler.proceed();
}

免责声明:我这样做是为了测试,因为这是测试版。对于严肃的事情来说,这可能不是一个好主意。然而,Android WebView 如何与 SSL 配合使用似乎存在一些混乱。对于感兴趣的人,以下链接可能有用:https://stackoverflow.com/a/5978391/780694 和 <一个href="http://r3gis.fr/blog/index.php?post/2009/11/17/Android-WebView-and-ssl-self-signed-certificates" rel="nofollow noreferrer">http:// r3gis.fr/blog/index.php?post/2009/11/17/Android-WebView-and-ssl-self-signed-certificates

Solved it. It was the Authentication after all. After trying all the authentication methods for WebView, I switched to SSL.

The certificate was causing a problem which I was able to bypass using the following method override in the WebViewClient.

@Override
public void onReceivedSslError(WebView view,
                SslErrorHandler handler, SslError error) {
Log.e("Error", "Received SSL error"+ error.toString());
handler.proceed();
}

Disclaimer: I'm doing this for testing as this is a beta. This would probably not be a good idea on something serious. However, there seems to be some confusion over how Android WebView works with SSL. For anyone interested, the following links may be useful: https://stackoverflow.com/a/5978391/780694 and http://r3gis.fr/blog/index.php?post/2009/11/17/Android-WebView-and-ssl-self-signed-certificates

清欢 2025-01-04 08:22:36


Uri 类的 parse() 方法将 URL 字符串转换为 Uri 对象。

 public void onReceivedSslError(WebView view,
    SslErrorHandler handler, SslError error) {
 Log.e("Error", "Received SSL error"+ error.toString());
 handler.proceed();
}

the
parse() method of the Uri class to convert an URL string into an Uri object.

 public void onReceivedSslError(WebView view,
    SslErrorHandler handler, SslError error) {
 Log.e("Error", "Received SSL error"+ error.toString());
 handler.proceed();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文