Android WebView:onreceivedHttpError statusCode == 404

编程入门 行业动态 更新时间:2024-10-27 10:24:38
本文介绍了Android WebView:onreceivedHttpError statusCode == 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

代码如下:

    @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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 04:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1129055.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WebView   Android   onreceivedHttpError   statusCode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!