imho:Apache HTTP客户端
用法示例:
import org.apache.commons.httpclient.*;import org.apache.commons.httpclient.methods.*;import org.apache.commons.httpclient.params.HttpMethodParams;import java.io.*;public class HttpClientTutorial { private static String url = "http://www.apache.org/"; public static void main(String[] args) { // Create an instance of HttpClient. HttpClient client = new HttpClient(); // Create a method instance. GetMethod method = new GetMethod(url); // Provide custom retry handler is necessary method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); try { // Execute the method. int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { System.err.println("Method failed: " + method.getStatusLine()); } // 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)); } catch (HttpException e) { System.err.println("Fatal protocol violation: " + e.getMessage()); e.printStackTrace(); } catch (IOException e) { System.err.println("Fatal transport error: " + e.getMessage()); e.printStackTrace(); } finally { // Release the connection. method.releaseConnection(); } }}一些重要功能:
- 基于标准的纯Java,HTTP版本1.0和1.1的实现
- 在可扩展的OO框架中完全实现所有HTTP方法(GET,POST,PUT,DELETE,HEAD,OPTIONS和TRACE)。
- 支持使用HTTPS(基于SSL的HTTP)协议进行加密。
- 粒度非标准配置和跟踪。
- 通过HTTP代理的透明连接。
- 通过CONNECT方法通过HTTP代理建立的隧道HTTPS连接。
- 使用本机Java套接字支持通过SOCKS代理(版本4和5)进行透明连接。
- 使用基本,摘要和加密NTLM(NT Lan Manager)方法进行身份验证。
- 自定义身份验证方法的插件机制。
- 多部分表单POST,用于上传大文件。
- 可插拔安全套接字实施,使使用第三方解决方案更加容易
- 连接管理支持在多线程应用程序中使用。支持设置最大总连接数以及每个主机的最大连接数。检测并关闭陈旧的连接。
- 自动cookie处理,用于从服务器读取Set-cookie:标头,并在适当时在cookie:标头中发回。
- 自定义cookie策略的插件机制。
- 请求输出流以避免通过直接流到服务器的套接字来缓冲任何内容主体。
- 响应输入流通过直接从套接字流传输到服务器来有效读取响应主体。
- 在HTTP / 1.0中使用KeepAlive的持久连接以及在HTTP / 1.1中的持久性
- 直接访问服务器发送的响应代码和标头。
- 设置连接超时的能力。
- HttpMethods实现了命令模式,以允许并行请求和有效的连接重用。
- 源代码可根据Apache软件许可免费获得。



