Android WebView : onreceivedHttpError statusCode == 404

我的未来我决定 提交于 2019-12-12 04:15:50

问题


Here is the code:

    @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 always got the 404 error (errorResonse.getStatusCode() == 404), but url even work fine on Chrome

thanks for any comments.


回答1:


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)

... 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

... 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. ...



来源:https://stackoverflow.com/questions/45432583/android-webview-onreceivedhttperror-statuscode-404

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!