开发者

How to get the source code from a HttpClient HttpResponse?

Here is my HttpClient request:

 HttpClient htt开发者_开发问答pclient = 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?


HttpResponse response = httpclient.execute(httppost);
HTML = EntityUtils.toString(response.getEntity());


There you go:

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


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜