Android WebView:onreceivedHttpError statusCode == 404 [英] Android WebView : onreceivedHttpError statusCode == 404

查看:69
本文介绍了Android WebView:onreceivedHttpError statusCode == 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码如下:

    @Override
    @SuppressWarnings("deprecation")
    public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
        ****
    }
    @Override
    @TargetApi(Build.VERSION_CODES.M)
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        ***
    }

    @Override
    @TargetApi(Build.VERSION_CODES.M)
    public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
        ***
    }

onReceivedHttpError 总是得到 404 错误(errorResonse.getStatusCode() == 404),但 url 甚至在 Chrome 上工作正常

onReceivedHttpError always got the 404 error (errorResonse.getStatusCode() == 404), but url even work fine on Chrome

感谢您的任何评论.

推荐答案

您可能会看到网站上特定项目的错误,而不是整个网页本身.从文档中,您可以参考以下方法的描述:

You may be seeing errors for specific items on the website instead of the whole webpage itself. From the docs, you can refer to the description of the methods as follows:

onReceivedError (API 23)

... 请注意,与已弃用的回调版本不同,新的任何资源(iframe、图像等)都会调用 version,而不仅仅是为主页.因此,建议执行最低要求在这个回调中工作.

... Note that unlike the deprecated version of the callback, the new version will be called for any resource (iframe, image, etc), not just for the main page. Thus, it is recommended to perform minimum required work in this callback.

onReceivedHttpError

... 任何资源(iframe、图像、等),而不仅仅是主页.因此,建议执行此回调中所需的最少工作....

... This callback will be called for any resource (iframe, image, etc), not just for the main page. Thus, it is recommended to perform minimum required work in this callback. ...

这篇关于Android WebView:onreceivedHttpError statusCode == 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆