- 论坛徽章:
- 0
|
HttpClient介绍
The Hyper-Text Transfer Protocol (HTTP) is perhaps the most significant protocol used on the Internet today. Web services, network-enabled appliances and the growth of network computing continue to expand the role of the HTTP protocol beyond user-driven web browsers, while increasing the number of applications that require HTTP support.
Although the java.net package provides basic functionality for accessing resources via HTTP, it doesn't provide the full flexibility or functionality needed by many applications. The Jakarta Commons HttpClient component seeks to fill this void by providing an efficient, up-to-date, and feature-rich package implementing the client side of the most recent HTTP standards and recommendations. See the
Features
page for more details on standards compliance and capabilities.
Designed for extension while providing robust support for the base HTTP protocol, the HttpClient component may be of interest to anyone building HTTP-aware client applications such as web browsers, web service clients, or systems that leverage or extend the HTTP protocol for distributed communication.
There are many projects that use HttpClient to provide the core HTTP functionality. Some of these are open source with project pages you can find on the web while others are closed source that you would never see or hear about. The Apache Source License provides maximum flexibility for source and binary reuse. Please see the
Applications
page for projects using HttpClient. (
http://hc.apache.org/httpclient-3.x/
)
对于使用静态页面能够直接使用简单的程序得到页面,对于动态页面需要使用另外的一种方式,很多方法可以使用HttpClient方式,HttpClient能够模拟页面中的Post和Get方式,对于动态页面提交参数,然后接受返回的页面,保存处理。具体的代码如下:
public static String getNext(HttpClient client, String s) throws HttpException, IOException {
PostMethod post = new PostMethod("list.aspx");
NameValuePair[] data = new NameValuePair[3];
data[0] = new NameValuePair("__EVENTTARGET", "lbNextPage");
data[1] = new NameValuePair("__EVENTARGUMENT", "");
data[2] = new NameValuePair("__VIEWSTATE", s);
post.setRequestBody(data);
client.executeMethod(post);
String s1;
s1 = post.getResponseBodyAsString();
return s1;
}
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/3176/showart_1421843.html |
|