【问题标题】:Download Data Using HTTPClient使用 HTTPClient 下载数据
【发布时间】:2020-03-30 03:11:49
【问题描述】:

有一个关于使用 Apache HTTPClient 的问题。我需要从网站上提取数据,发现这个有用的教程https://hc.apache.org/httpclient-3.x/tutorial.html

在教程中它说我们将编写一个“下载页面”的简单应用程序。

它究竟将页面“下载”到哪里?我没有看到有人提到正在设置数据库或一些云存储或诸如此类的信息,所以信息究竟“去”在哪里(或者一旦数据被提取,它被保存在哪里)?我对 Java 有点陌生,所以这有点概念化

【问题讨论】:

    标签: java httpclient


    【解决方案1】:

    “下载”转到System.out

      // Read the response body.
      byte[] responseBody = method.getResponseBody();
    
      // Deal with the response.
      // Use caution: ensure correct character encoding and is not binary data
      System.out.println(new String(responseBody));
    

    【讨论】:

    • 太棒了...非常感谢。我以前从未想过这一点,并且总是不假思索地使用 system.out.println。这实际上巩固了我在 OOP 和工程方面的理解。
    猜你喜欢
    • 1970-01-01
    • 2011-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多