gpt4 book ai didi

java - Webview 不加载 html 或 javascript Android

转载 作者:行者123 更新时间:2023-11-28 13:55:04 26 4
gpt4 key购买 nike

我正在检索从 HttpGet 获得的页面的整个 html 和 javascript。我可以成功获取 Html 和 Javascript。当我尝试将其加载到 Web View 中时,Web View 显示“页面不可用”,并显示将以一种非常奇怪的格式加载的 html 和 javascript,元素之间有百分比。我确信 html 和 javascript 正在被下载并以 Html 页面的形式出现。我还在 WebView 中启用了 javascript。什么可能导致这样的问题?代码:

public void parseDoc() {
new Thread(new Runnable() {

@Override
public void run() {
String summary = "<html><body>You scored <b>192</b> points.</body></html>";
sting.loadData(summary, "text/html", null);
HttpParams params = new BasicHttpParams();
HttpClientParams.setRedirecting(params, true);
httpclient = new DefaultHttpClient();

httppost = new HttpPost(
"https://secure.groupfusion.net/processlogin.php");
String HTML = "";
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
3);
nameValuePairs
.add(new BasicNameValuePair(
"referral_page",
"/modules/gradebook/ui/gradebook.phtml?type=student_view&jli=t&jli=t&jli=t&jli=t&jli=t&jli=t&printable=FALSE&portrait_or_landscape=portrait"));
nameValuePairs.add(new BasicNameValuePair("currDomain",
"beardenhs.knoxschools.org"));
nameValuePairs
.add(new BasicNameValuePair("username", user));
nameValuePairs
.add(new BasicNameValuePair("password", pass));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);
HTML = EntityUtils.toString(response.getEntity());
Document doc = Jsoup.parse(HTML);
Element link = doc.select("a").first();
linkHref = link.attr("href");

HttpGet request = new HttpGet();
try {
request.setURI(new URI(linkHref));

} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response = httpclient.execute(request);

InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line);
}
in.close();
HTML = str.toString();
sting.loadData(HTML, "text/html", null);

} catch (ClientProtocolException e) {
} catch (IOException e) {
}

}
}).start();

}

最佳答案

尝试使用以下方法加载WebView

mWebView.loadDataWithBaseURL(null, htmlString,"text/html", "utf-8", null);

关于java - Webview 不加载 html 或 javascript Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8514505/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com