【问题标题】:How to get the source code from a HttpClient HttpResponse?如何从 HttpClient HttpResponse 中获取源代码?
【发布时间】:2011-07-26 03:08:37
【问题描述】:

这是我的 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 字符串?

【问题讨论】:

    标签: java httpclient http-post httpresponse


    【解决方案1】:
    HttpResponse response = httpclient.execute(httppost);
    HTML = EntityUtils.toString(response.getEntity());
    

    【讨论】:

      【解决方案2】:

      你去吧:

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

      【讨论】:

        【解决方案3】:

        您可以通过从httpresponse.getEntity().getContent();读取流来获取响应html

        不知何故,我认为这可能无法回答您的问题,因为您使用了“源代码”一词。

        【讨论】:

          猜你喜欢
          • 2016-02-28
          • 2018-01-26
          • 1970-01-01
          • 2012-04-22
          • 1970-01-01
          • 2020-10-16
          • 2015-09-05
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多