Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the source code from a 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 fill the HTML string with the source code of the request?

like image 346
Qasim Avatar asked Dec 28 '22 16:12

Qasim


2 Answers

HttpResponse response = httpclient.execute(httppost);
HTML = EntityUtils.toString(response.getEntity());
like image 182
citizen conn Avatar answered Dec 30 '22 04:12

citizen conn


There you go:

String html = org.apache.http.util.EntityUtils.toString( response.getEntity() );
like image 27
Maurício Linhares Avatar answered Dec 30 '22 04:12

Maurício Linhares