我正在尝试编译以下代码(以查看是否可以使Web服务器流式传输到客户端):

           HttpClient httpClient = new HttpClient();

           HttpRequest req = new HttpRequest("GET", "http://tools.ietf.org/html/rfc2616.html");

           // returns immediately if the complete header (not message!) is received
           HttpResponse resp = httpClient.call(req);

           if (resp.getStatus() == 200) {
              // create the output file
              File file = new File("rfc2616.html");
              file.createNewFile();
              FileChannel fc = new RandomAccessFile(file, "rw").getChannel();

              // get a blocking message body channel
              ReadableByteChannel inputBodyChannel = resp.getBlockingBody();

              // and transfer the data
              fc.transferFrom(inputBodyChannel, 0, 900000);
              fc.close();
           }


但是eclipse无法识别HTTPRequest类,即使我将所有apache .jar添加到了我的构建路径中,我也没有任何支持它的apache jar?

最佳答案

那就是HttpComponents Client 4.x API。您可以下载它here。也许您使用的是3.x版本,但确实缺少HttpRequest类。

10-08 06:21
查看更多