繁体   English   中英

Webview无法加载html或javascript Android

[英]Webview not loading html or javascript Android

我正在检索从HttpGet获得的页面的整个html和javascript。 我可以成功获取HTML和Javascript。 当我尝试将其加载到Web视图中时,Web视图显示“页面不可用”,并显示要以一种非常古怪的格式加载的html和javascript,其中各元素之间存在百分比。 我很肯定正在下载html和javascript并以HTML页面的形式显示。 我还在网络视图中启用了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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM