Reputation: 40416
How to show response in webview?
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mymobilece.com/api/api_getexammaterials.php?id=27");
HttpResponse response = httpclient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());
System.out.println("Respnce body :: " + responseBody);
bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer stringBuffer = new StringBuffer("");
String line = "";
String LineSeparator = System.getProperty("line.separator");
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line + LineSeparator);
}
bufferedReader.close();
Toast.makeText(View_Materials_Activity.this, "Finished", Toast.LENGTH_LONG).show();
String webData = stringBuffer.toString();
String webData1 = URLDecoder.decode(webData);
System.out.println("data :; " + webData1);
webView.loadData(webData, "text/html", "UTF-8");
webView.loadDataWithBaseURL("http://www.ilias.de/docu/", webData,"text/html", "UTF-8", "about:blank");
Responce body ::
ýb>&ª4+ü"ðÐôí{Á>
Ó~5xGåYxôùuo_xƾԧ¶·:7<5áË]SKפÿ��^ Ï|ÿ��si÷ú©þÏî|9â©,u¿ê±x+ámö§¨kW?4¸ÔE¼>){íTÑ|Cá{-SÄ^Õ´ý+Ç~Õ¼'w6¯¡Ú.+ [ðã§üãâ-¶ºÚìá¦ø"ÖÏá÷>+êñøá¿Ã#IÃÚF¥üWñ
¼ºâSÂñê7?Ä[_Ï¢êZ¥1_Qiü¿ìÍpé Gìéû`þÇ÷Þ:ðÿ��þ|×<«|GÔí< ·¤xoáôíAü9ê|òÁ㨵KëOIñ/L¾N¶Ónu;ujþÒu{
Äv?üàü%±xCLðÅO\Ïñg_ø+±áA×ôãíOÛ&6¡¥ø¢èÚ[jÚ¼3¥Ø_]üzÆ£m¨½hz¹´��ð_~Û?°¤(ñ ðwÀ;KVñ&¥©x+ÄÖái¦xRøªøÏÄz
ö§ãë;
\xÿ��ì¾3Öåá¤Ò|A}¨
ûBó_ñ.¤ßr¾%øßûüøýã_º§ìð÷Â^ð:õ¯é'Ã;»[Ãþð×Å5}2ïQÒeÁÚì_õË[=SV¸å¼Eý¨5K4ÐuYõ6ü=ñçö?õZo졦Ùü/o|?¶Ðt¿^îæ×IýücûBÜøÿ��Â]°¶Ó´oü<ñ×Åm:&¾×EÞ«®izsiâ¸ìÿ��µ¯ì?áÝOZðÝ¿ìÉ«C®|bѼ'¢x×NÓ¼ð¢óþO\é®{©ê67Jø¦Yi~Õ<]âØôâOÚè¾xÛþØ?°Gü%àßZþËlzçf·Ñ|5
§>èÑ뺤øuâ~h<Ï_j:Gôý2_ éz-íô-/J¸GobäMøïûů|CÔ.gOVñ£ûB|Bñ§ü
Upvotes: 0
Views: 6422
Reputation: 36302
As you can see, an HTTP response is not HTML. It's HTTP. It might contain HTML. Use HttpResponse.getEntity
and then Entity.getContent
and you can read the data (presumably HTML) from the stream. Then you can use WebView.loadData
to load that data.
Update: Your data might also be gzipped... Take a look at this other SO post for more details.
Upvotes: 3