Android WebView:onreceivedHttpError statusCode == 404

时间:2017-08-01 08:23:03

标签: android webview http-error

以下是代码:

    @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上工作正常

感谢任何评论。

1 个答案:

答案 0 :(得分:0)

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

onReceivedError(API 23)

  

...请注意,与不推荐使用的回调版本不同,新版本   将为任何资源(iframe,图像等)调用版本,而不仅仅是   对于主页面。因此,建议执行最低要求   在这个回调中工作。

<强> onReceivedHttpError

  

...将为任何资源调用此回调(iframe,图像,   等),而不仅仅是主页面。因此,建议执行   此回调中所需的最低工作量。 ...