android - WebView:加载 url 时请求错误

标签 android webview

当我尝试在 WebView 中加载 URL 时:

private final WebViewClient webViewClient = new WebViewClient() {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        loadUrl(url);
        return true;
    }
};
webView.setWebViewClient(webViewClient);
webView.loadUrl("https://post.craigslist.org/");

我在页面上得到这个 html:

Bad Request

Your browser sent a request that this server could not understand.

enter image description here

onReceivedError(WebView view, int errorCode, String description, String failingUrl) 回调中也没有任何内容。

最佳答案

它给你这个错误是因为你没有正确处理来自这个网页的重定向 试试这个

webview.setWebViewClient(new WebViewClient() {
  public boolean shouldOverrideUrlLoading(WebView view, String url){
    // do your handling codes here, which url is the requested url
    // probably you need to open that url rather than redirect:
    view.loadUrl(url);
    return false; // then it is not handled by default action
 }
});

关于android - WebView:加载 url 时请求错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26795503/

相关文章:

java - Webview 后退按钮(goback)不起作用

ios - 如何在 Swift 的 WKWebView 中禁用用户选择?

android - Android 操作栏中的自定义大 Logo

java - 如何从 WebView 中获取文本

java - 使用 OpenCv 和 android 进行图像识别

android - Recyclerview 滚动滞后

android - TabHost\WebView 嵌入式 youtube 视频 float 问题

javascript - Android 3.x 仅限 WebView 文本选择 + JavaScript

java - 导航栏中的底部按钮是什么,您有时会看到它用于更改设置

java - 使用 zxing 对随机字节数组进行编码和解码