Android Webview - 给出“对象移动到”重定向时
我在我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这总是让我感到困惑,但要解释一下......
当一个新的 url 即将出现时被加载时,会调用该方法。如果返回
true
则主机应用程序将处理该 url。换句话说,返回 true 告诉主机应用程序它应该覆盖 url 加载 - 这可能会导致重定向或调用常用浏览器。据我所知,这不是您想要的。您应该返回
false
向主机应用程序表明您的WebView
已处理它,并且主机应用程序不应覆盖 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, returningtrue
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 yourWebView
has handled it and that the host application SHOULD NOT override url loading.解决了。毕竟是认证。在尝试了 WebView 的所有身份验证方法后,我切换到了 SSL。
该证书导致了一个问题,我可以使用 WebViewClient 中的以下方法覆盖来绕过该问题。
免责声明:我这样做是为了测试,因为这是测试版。对于严肃的事情来说,这可能不是一个好主意。然而,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.
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
这
Uri 类的 parse() 方法将 URL 字符串转换为 Uri 对象。
the
parse() method of the Uri class to convert an URL string into an Uri object.