吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 8859|回复: 9
收起左侧

[其他转载] JAVA 写的,自动登录论坛,发送短消息

 关闭 [复制链接]
my26929 发表于 2010-8-10 19:59
package renren;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.Set;

import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class BaiyouBBS {
static final String LOGON_SITE = "bbs.baiyou100.com";

static final int LOGON_PORT = 80;

@SuppressWarnings("deprecation")
public Cookie[] login(String name, String pas) {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
PostMethod post = new PostMethod("http://bbs.baiyou100.com/login.aspx");
NameValuePair username = new NameValuePair("username", name);
NameValuePair password = new NameValuePair("password", pas);
post.setRequestBody(new NameValuePair[] { username, password });
try {
System.out.println("准备登陆");
client.executeMethod(post);
System.out.println("开始登陆");
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String responseString = null;
try {
responseString = new String(post.getResponseBodyAsString()
.getBytes("gb2312"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Cookie[] cookies = client.getState().getCookies();
client.getState().addCookies(cookies);
post.releaseConnection();
Set set = new UserList().getUserList();

// 遍历集合
Iterator it = set.iterator();
for (; it.hasNext();) {
String sName = (String) it.next();
// 提交短
System.out.println("提交短消息");
post = new UTF8PostMethod("http://bbs.baiyou100.com/usercppostpm.aspx");
NameValuePair names = new NameValuePair("msgto", sName);
NameValuePair biaoti = new NameValuePair("subject", "“"+sName+"标题");
NameValuePair neirong = new NameValuePair("message","内容 ");
NameValuePair sendmsg = new NameValuePair("sendmsg","%E7%AB%8B%E5%8D%B3%E5%8F%91%E9%80%81");
post.setRequestBody(new NameValuePair[] { names, biaoti, neirong,sendmsg });
post.setRequestHeader("Referer","http://bbs.baiyou100.com/usercppostpm.aspx");
post.setRequestHeader("Accept-Language", "zh-cn");
try {
client.getState().addCookies(cookies);
client.executeMethod(post);
responseString = new String(post.getResponseBodyAsString().getBytes("gb2312"));
if(responseString.lastIndexOf("发送完毕")>=0){
System.out.println(sName+" - OK");
}
} catch (HttpException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return null;
}

public static void main(String[] args) {
new BaiyouBBS().login("账号", "密码");
}

}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

77413036 发表于 2010-8-10 20:14
本帖最后由 77413036 于 2010-8-10 20:18 编辑

哎,又是JAVA,天天面对的个JAVA , 天天用个鬼eclipse做JSP ,报一些莫名其妙的错。头大。。

现在又见JAVA,是那么的熟悉,那么的亲切,那么的令我蛋疼。。

以上观点纯属墨迹。与楼主无关。。。

感谢分享。。
Hmily 发表于 2010-8-10 20:50
xxm16429 发表于 2010-8-11 22:09
1270052418 发表于 2011-3-3 15:46
怎么用啊
残风恋 发表于 2011-3-5 22:52
我也在学JAVA 但是我是初级的 呵呵,
necessary8 发表于 2011-4-14 16:09
学习中  虽然java的环境 相对于其他语言的环境 麻烦些  但其跨平台性是不错的
yuxiong 发表于 2012-2-17 19:50
先收藏了
wubudomain 发表于 2012-2-22 20:33
呵呵,写得不错。。
mhjdg 发表于 2012-2-23 00:29
我还是学c吧
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-16 17:27

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表