java - 如何从 HttpClient HttpResponse 获取源代码?

标签 java httpclient http-post httpresponse

这是我的 HttpClient 请求:

 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) {} 

如何用请求的源代码填充 HTML 字符串?

最佳答案

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

关于java - 如何从 HttpClient HttpResponse 获取源代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6824802/

相关文章:

java - HTTP客户端408状态码

react-native-ssl-pinning - 此服务器的证书无效

c++ - POCO如何发送XML数据?

java - 使用 Http 代理通过抢占式身份验证连接到主机

java - 如何让 selenium(Chrome) webdriver 等待,直到网络中没有待处理的请求? (使用JAVA)

java - 如何从终端执行 .jar 文件而不指定其名称

Java:LibGdx TileMapTile 在嵌套 for 循环中使用后未获取属性

java - Google Analytics 中没有事件跟踪

java - 如何使用java通过HttpPost发送空的二进制数据

java - 如何将 List<String> 作为 Intent extra 传递?