How to get source code from HttpClient HttpResponse?

Here is my HttpClient request:

HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.***.**/***/***_***.php"); String HTML = ""; try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("from", contactName)); nameValuePairs.add(new BasicNameValuePair("msg", message)); nameValuePairs.add(new BasicNameValuePair("sent", time_sent)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HTML = "How?"; } catch (ClientProtocolException e) {} catch (IOException e) {} 

How can I populate an HTML string with the request source code?

+4
source share
3 answers
 HttpResponse response = httpclient.execute(httppost); HTML = EntityUtils.toString(response.getEntity()); 
+5
source

There you go:

 String html = org.apache.http.util.EntityUtils.toString( response.getEntity() ); 
+4
source

You can get the html response by reading the stream from httpresponse.getEntity().getContent();

Somehow I think that this may not answer your question, because you use the word "source code".

+1
source

All Articles