2015-07-03 18 views
0

我必須作出一個呼叫HTTP GET當用戶登錄在某個URL,並查看GETWebView的HTTP GET調用的API和觀看關於web視圖

PlayBack.java響應的結果( WebView):

public class PlayBack extends Activity { 
    WebView wv; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     //setContentView(R.layout.play_back); 
     wv = new WebView(this); 
     wv.setWebViewClient(new CustomWebView()); 
    } 

    private class CustomWebView extends WebViewClient{ 
     @Override 
     public boolean shouldOverrideUrlLoading(WebView view, String url) { 
      Intent intent = getIntent(); 
      String id = intent.getStringExtra("pid"); 
      String playUrl = "certain url"+id; 
      String htmlCon = ""; 
      HttpGet httpGet = new HttpGet(playUrl); 
      try{ 
       HttpResponse httpResponse = MainActivity.httpClient.execute(httpGet); 
       HttpEntity httpEntity = httpResponse.getEntity(); 
       InputStream inputStream = httpEntity.getContent(); 
       htmlCon = convertToString(inputStream); 
       wv.loadData(htmlCon, "text/html", "utf-8"); 
      }catch(Exception e) { 

      } 
      return false; 
     } 
    } 

    public String convertToString(InputStream inputStream){ 
     StringBuffer string = new StringBuffer(); 
     BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 
     String line=""; 
     try { 
      while ((line = reader.readLine()) != null) { 
       string.append(line + "\n"); 
      } 
     } catch (Exception e) {} 
     return string.toString(); 
    } 
} 

但是我在視圖上看不到任何東西。我發現上面的代碼here.

回答

0

試試這個:

webView.loadData(html, "text/html", null); 

其中HTML ==來自服務器的原始HTML字符串響應。

0

使用loadDataWithBaseURL代替loadData

webview.loadDataWithBaseURL("", htmlcon, "text/html", "UTF-8", null); 
+0

仍然沒有解決。 –