I am retrieving the whole html and javascript of a page I get from an HttpGet. I can successfully get the Html and the Javascript. When I try and load it into the web view, the web view gives me "Page not available" and shows the html and javascript that was to be loaded in a really weird format with percentages in between the elements. I am positive the html and javascript is being downloaded and in the shape of an Html page. I have also enabled javascript in the web view. What could be causing such a problem? Code:
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.