Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1327171
  • 博文数量: 115
  • 博客积分: 10011
  • 博客等级: 上将
  • 技术积分: 5785
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-28 09:13
文章分类
文章存档

2009年(23)

2008年(92)

我的朋友

分类: Java

2008-11-18 12:09:08

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 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 page for projects using HttpClient. ()

对于使用静态页面能够直接使用简单的程序得到页面,对于动态页面需要使用另外的一种方式,很多方法可以使用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;
    }

阅读(785) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~