利用httpclient模拟站点的登录发帖回复
2009-09-22 00:00:00 来源:WEB开发网KaixinSitePost类的代码:
1/** *//**
2 * Copyright (C): 2009
3 * @author 陈新汉
4 * Aug 14, 2009 11:16:32 AM
5 */
6
7/** *//**
8 * 模拟测试网站(不需要验证码)
9 * 开心网(www.kaixin.com)
10 */
11public class KaixinSitePost implements ISitePost
12{
13 private static final String LOGON_SITE = "www.kaixin.com";
14 private static final int LOGON_PORT = 80;
15 private static final String CHARSET="UTF-8";
16 private BrowserContext context=null;
17
18
19 //单个用户登录
20 public String login(Siteusers userinfo, Proxyips ip)
21 {
22 if(userinfo!=null)
23 {
24 SiteLogin login=new SiteLogin(context,"http://login.kaixin.com/Login.do");
25 if(ip!=null)
26 login.getContext().setProxyip(ip);
27 Map<String,String> params=new HashMap<String,String>();
28 params.put("ss", "10106");
29 params.put("loginregFrom", "index");
30 params.put("origURL", "http://www.kaixin.com/SysHome.do");
31 params.put("email", userinfo.getUsername());
32 params.put("password", userinfo.getUserpwd());
33 login.addRequestParameters(params);
34 return login.login(userinfo);
35 }
36 return null;
37 }
38
39 public List<Siteboards> parseBoard(Siteboards data) {
40
41 return null;
42 }
43
44 public String post(Postinfos postinfo,List<Siteboards> siteboards)
45 {
46 if(postinfo!=null && siteboards!=null){
47 SitePost sport=new SitePost(context);
48 context.getClient().getHostConfiguration().setHost("blog.kaixin.com");
49 Map<String,String> params=new HashMap<String,String>();
50 params.put("categoryId", "0");
51 params.put("blogControl", "1");
52 params.put("title", postinfo.getTitle());
53 params.put("body",postinfo.getContent());
54 sport.addRequestParameters(params);
55
56 for(Siteboards sb:siteboards){
57 sb.setPostUrl("http://blog.kaixin.com/NewEntry.do");
58 try{
59 sport.post(postinfo, sb);
60 }catch(IOException e){
61 e.printStackTrace();
62 }
63 }
64 }
65 return null;
66 }
67
68
69 public String reply(Postinfos postinfo,List<Articleinfos> arts)
70 {
71
72 return null;
73 }
74
75 /** *//**
76 * @param args
77 */
78 public static void main(String[] args)
79 {
80 try
81 {
82 Siteusers userinfo=new Siteusers();
83 userinfo.setUsername("xxxx");
84 userinfo.setUserpwd("xxxx");
85 Proxyips ips = new Proxyips();
86 ips.setIp("218.56.64.210");
87 ips.setPort(8080);
88 KaixinSitePost sp=new KaixinSitePost();
89 sp.login(userinfo,ips);
90 Postinfos post=new Postinfos();
91 post.setContent("<p>lllllllllllllllllllllll</p>");
92 post.setTitle("中文测试");
93 List<Siteboards> siteboards=new ArrayList<Siteboards>();
94 siteboards.add(new Siteboards());
95 siteboards.add(new Siteboards());
96 sp.post(post,siteboards);
97 }
98 catch(Exception e){
99 e.printStackTrace();
100 }
101 }
102}
Tags:利用 httpclient 模拟
编辑录入:爽爽 [复制链接] [打 印]赞助商链接