当我尝试在 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.
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/