如何从 HttpClient HttpResponse 获取源代码?

发布于 2024-11-26 14:00:32 字数 812 浏览 1 评论 0原文

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

日裸衫吸 2024-12-03 14:00:32
HttpResponse response = httpclient.execute(httppost);
HTML = EntityUtils.toString(response.getEntity());
HttpResponse response = httpclient.execute(httppost);
HTML = EntityUtils.toString(response.getEntity());
一袭水袖舞倾城 2024-12-03 14:00:32

就这样:

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

There you go:

String html = org.apache.http.util.EntityUtils.toString( response.getEntity() );
蓝天 2024-12-03 14:00:32

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

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

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文