httpclient最新版本
时间: 2024-01-22 11:02:59 浏览: 25
根据提供的引用内容,最新版本的HttpClient是3.1版本。以下是使用HttpClient 3.1发送同步HTTP请求的示例代码:
```java
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;
public class HttpClientExample {
public static void main(String[] args) {
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod("http://www.example.com");
try {
int statusCode = httpClient.executeMethod(getMethod);
if (statusCode == HttpStatus.SC_OK) {
String responseBody = getMethod.getResponseBodyAsString();
System.out.println(responseBody);
} else {
System.err.println("HTTP request failed: " + getMethod.getStatusLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
getMethod.releaseConnection();
}
}
}
```
请注意,这只是一个简单的示例,实际使用中可能需要根据具体需求进行配置和处理。如果您需要更多关于HttpClient的信息,请参考官方文档:http://hc.apache.org/httpclient-3.x/。