我们监控到的HTTP数据包有两个属性很重要:
POST :后面的东西,就是说这个请求处理的页面(URL)
Cokie:保持HTTP请求连续的标志,
还有一个也很重要:Referer,因为好多网站判断这个标志是否来自什么地方请求防止恶意注册,呵呵,知道该怎么做了吗?模拟你的请求吧!准备写个自动注册的东西,开始工作。寻找目标http://foxconnbbs.com/index.asp,呵呵,富士康的,我喜欢!随便找个帖子:http://foxconnbbs.com/dispbbs.asp?boardID=3&ID=3749&page=1注意URL参数的写法,这个和你自动生成所有的回帖有关,我就不在写这个Demo!只是真对这个帖子用Dot.Net实现外部提交!打开ieHTTPHeaders,分析下提交的数据格式:
呵呵,直到处理提交的URL: savepost.asp?action=sre&method=fastreply&BoardID=3,呵呵,别忘记前面加http://foxconnbbs.com/。为什么?晕到!Cookie也知道了吧!呵呵,提交的数据就是这一部分了。结下来就是如何模拟这个请求了,要想模拟这个请求,必须得出cookie的值,呵呵,如何得到这个Cookie哪?还得模拟登陆获得!看下登陆界面:
点击登录后注意提交数据,
呵呵,自己分析吧!
Ok!开始干活,自动登录获得Cookie的方法如下:
/**////
/// 正弦曲线Wave扭曲图片(Edit By 51aspx.com)
///
/// 图片路径
/// 如果扭曲则选择为True
/// 波形的幅度倍数,越大扭曲的程度越高,一般为3
/// 波形的起始相位,取值区间[0-2*PI)
///
public string ShamLogin(string url, string usr,string pwd)
{
string Return = null;
this.LoginUrl = url;
string loginstr = "username="+usr+"&password="+pwd+"&CookieDate=0&submit=%B5%C7%C2%BC";
loginstr = EncodePost(loginstr);
byte[] replybyte = Encoding.UTF8.GetBytes(loginstr);
try
{
CookieContainer testCC = new CookieContainer();
TestRequest = (HttpWebRequest)WebRequest.Create(url);
TestRequest.CookieContainer = testCC;
TestRequest.ContentType = "application/x-www-form-urlencoded";
TestRequest.Method = "POST";
TestRequest.ContentLength = replybyte.Length;
Stream newStream = TestRequest.GetRequestStream();
newStream.Write(replybyte, 0, replybyte.Length);
newStream.Close();
TestResponse = (HttpWebResponse)TestRequest.GetResponse();
Stream dataStream = TestResponse.GetResponseStream();
StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("gb2312"));
Return = reader.ReadToEnd();
// check cookie
foreach (Cookie temp in TestResponse.Cookies)
{
if (temp.Domain != "foxconnbbs.com")
temp.Domain = "foxconnbbs.com";
}
CkCollection = TestResponse.Cookies;
}
catch
{
return null;
}
return Return;
}
public string Reply(string url,string formhash,string title,string content)
{
//post.php?action=reply&fid=84&tid=45444&extra=page%3D1&replysubmit=yes HTTP/1.1
//formhash=dcf4e770&subject=%B6%F1%C6%F8&message=eqw
TestRequest = (HttpWebRequest)WebRequest.Create("http://foxconnbbs.com/savepost.asp?action=sre&method=fastreply&BoardID=3");
TestRequest.ContentType = "application/x-www-form-urlencoded";
TestRequest.Method = "POST";
TestRequest.Referer = "http://foxconnbbs.com/dispbbs.asp?boardid=3&id=3711&star=1";
TestRequest.KeepAlive = true;
TestRequest.AllowWriteStreamBuffering = false;
// set cookie
CookieContainer cookieCon = new CookieContainer();
TestRequest.CookieContainer = cookieCon;
TestRequest.CookieContainer.Add(CkCollection);
// get post value
//formhash=dcf4e770&subject=%B6%F1%C6%F8&message=eqw
string reply = EncodePost("Body=%A3%BF%A3%BF%A3%BF&followup=18085&RootID=3711&star=1&TotalUseTable=dv_bbs1&UserName=roping&Expression=face1.gif&signflag=1&Submit=OK%21%B7%A2%B1%ED%BB%D8%B8%B4");
byte[] replybyte = Encoding.UTF8.GetBytes(reply);
TestRequest.ContentLength = replybyte.Length;
Stream newStream = TestRequest.GetRequestStream();
newStream.Write(replybyte, 0, replybyte.Length);
newStream.Close();
// get response
TestResponse = (HttpWebResponse)TestRequest.GetResponse();
Stream dataStream = TestResponse.GetResponseStream();
StreamReader reader = new StreamReader(dataStream, Encoding.GetEncoding("gb2312"));
string tt = reader.ReadToEnd();
reader.Close();
dataStream.Close();
TestResponse.Close();
return tt;
}
测试通过,完整代码如下:/Files/Roping/HTTPDemo.rar
CIO之家 www.ciozj.com 公众号:imciow