2011-12-15 10 views
0

HttpGetから取得したページ全体のHTMLとjavascriptを取得しています。私は正常にHTMLとJavascriptを得ることができます。私が試して、Webビューに読み込むと、Webビューは "ページが利用できません"と表示し、要素間にパーセンテージで本当に奇妙な形式で読み込まれていたhtmlとjavascriptを表示します。私はhtmlとjavascriptがダウンロードされ、HTMLページの形をしていると肯定的です。私はまた、Webビューでjavascriptを有効にしました。このような問題を引き起こす原因は何ですか?コード:Webviewで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(); 

} 

答えて

5

は、以下の方法

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

を使用してのWebViewをロードしてみますありがとうございました。それは働いた:D – Eli

+0

+1 ...素敵な答え:D – mAc

+0

ありがとう...本当に私を助けた... –

関連する問題