免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1261 | 回复: 0
打印 上一主题 下一主题

使用HttpClient取页面 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-18 12:09 |只看该作者 |倒序浏览
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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP