web视图不加载HTML或JavaScript的Andr​​oid [英] Webview not loading html or javascript Android

查看:138
本文介绍了web视图不加载HTML或JavaScript的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检索页面我从HTTPGET得到全HTML和JavaScript。我可以成功获取HTML和JavaScript。当我尝试并将其加载到网络视图,web视图给我页面不可用,并显示了HTML和JavaScript,这是在与各元素之间的百分比一个非常奇怪的格式来加载。我肯定的HTML和JavaScript正在下载和在HTML页面中的形状。我还启用了Web视图的JavaScript。什么可能会造成这样的问题? code:

 公共无效parseDoc(){
    新主题(新的Runnable接口(){        @覆盖
        公共无效的run(){
            字符串摘要=< HTML><车身>您打进< B> 192< / B>点< / BODY>< / HTML>中;
            sting.loadData(总结,text / html的,NULL);
            的HttpParams PARAMS =新BasicHttpParams();
            HttpClientParams.setRedirecting(参数,可以真正的);
            HttpClient的=新DefaultHttpClient();            httppost =新HttpPost(
                    https://secure.groupfusion.net/processlogin.php);
            串的HTML =;
            尝试{
                清单<&的NameValuePair GT; namevaluepairs中=新的ArrayList<&的NameValuePair GT;(
                        3);
                namevaluepairs中
                        。新增(新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(新BasicNameValuePair(currDomain
                        beardenhs.knoxschools.org));
                namevaluepairs中
                        。新增(新BasicNameValuePair(username的用户));
                namevaluepairs中
                        。新增(新BasicNameValuePair(密码,通));
                httppost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));                HTT presponse响应= httpclient.execute(httppost);
                的HTML = EntityUtils.toString(response.getEntity());
                文档的文档= Jsoup.parse(HTML);
                元件连结= doc.select(A)的第一();
                linkHref = link.attr(HREF);                HTTPGET请求=新HTTPGET();
                尝试{
                    request.setURI(新的URI(linkHref));                }赶上(的URISyntaxException E){
                    // TODO自动生成catch块
                    e.printStackTrace();
                }
                响应= httpclient.execute(请求);                。InputStream的时间= response.getEntity()的getContent();
                读者的BufferedReader =新的BufferedReader(
                        新的InputStreamReader(中));
                StringBuilder的海峡=新的StringBuilder();
                串线= NULL;
                而((行= reader.readLine())!= NULL){
                    str.append(线);
                }
                附寄();
                的HTML = str.toString();
                sting.loadData(HTML,text / html的,NULL);            }赶上(ClientProtocolException E){
            }赶上(IOException异常五){
            }        }
    })。开始();}


解决方案

尝试使用下面的方法来加载web视图

  mWebView.loadDataWithBaseURL(NULL,htmlString,text / html的,UTF-8,NULL);

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();

}

解决方案

Try to load WebView using following method

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

这篇关于web视图不加载HTML或JavaScript的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆