使用HttpClient实现基于WEB的第三方登录验证
2012-04-29张铁头马丽霞
张铁头 马丽霞
摘要:WEB应用经常需要用户登录才能进行操作,这要求必须先是其已注册用户。但有些情况下希望的用户只限于某个第三方网站已有的合法用户。如果第三方网站提供用户数据库或者诸如WEBService类接口,非常容易实现,否则就需要新的解决办法。HttpClient是一个开源的组件,实现了完整的WEB客户端编程能力,可以通过HttpClient模拟用户向第三方网站提交用户名密码等验证信息,然后根据返回的登录结果页面内容中是否包含相关的关键字来判断用户是否合法。
关键词:HttpClient;java;登陆验证
中图分类号:TP311文献标识码:A文章编号:1009-3044(2012)07-2779-02
Third-party Login Authentication with HttpClient Based WEB
ZHANG Tie-tou1,MA Li-xia2
(1.Henan Polytechnic Department of Information Engineering, Zhengzhou 450046, China; 2. Henan Star Hi-Tech Company Limited, Zhengzhou 450001, China)
Abstract: WEB applications often require a user to log in order to operate, so that this user must be registered before. But in some cases the user should be a legitimate user of a third-party websites. If the third party website to provide database or interfaces such as WebService class, it is easy to implement, otherwise new solutions should be resolved. HttpClient is an open-source components to achieve a complete Web client-side programming capabilities, user name, passwords and other authentication information is submitted through the HttpClient simulation users to third-party websites, and then return results of the login page content words to determine whether the user is legitimate. Key words: HttpClient; java; login authentication
一般的情况下我们都是使用IE或者Firefox等浏览器来访问一个WEB服务器,用来浏览页面查看信息或者提交一些数据等等。但是有时我们需要通过程序来模拟这种操作,比如用户在我们的网站输入用户名密码等验证信息,我们的WEB服务器接收到验证信息后模拟用户把验证信息提交给第三方网站的登录验证页面,根据第三方网站返回的验证结果页面中的关键字可以判断用户是否是允许的用户。甚至我们可以在用户登录成功后访问第三方网站的其它授权保护页面提取我们需要的信息为我们网站所用。该文以一个论文选题系统的登录验证为例来说明通过HttpClient组件来实现基于WEB的第三方验证。
1关键技术
1.1 HttpClient
HttpClient是Apache Jakarta Common下的子项目,用来提供高效的、最新的、功能丰富的支持HTTP协议的客户端编程工具包,并且它支持HTTP协议最新的版本和建议。……
