|
网站描述:打开网站输入用户名、密码、验证码,可以获取到验证码图片POST的时候把隐藏域内容也提交了但是,不能进入到Main.aspx。
private void button1_Click(object sender, EventArgs e)
{
try
{
string url = "http://xxxx.xxxx.cn/Admin/AdminLogin.aspx";
HttpHelper http=new HttpHelper();
HttpItem item = new HttpItem();
item.Accept = "text/html,application/xhtml+xm…ml;q=0.9,image/webp,*/*;q=0.8";
item.URL = url;
item.Method = "get";
item.ResultCookieType = ResultCookieType.CookieCollection;
HttpResult result = http.GetHtml(item);
htmllogin = result.Html;
cc.Add(result.CookieCollection);
string urlcode = "http://[size=14.3999996185303px]xxxx.xxxx.cn/Admin/ValidityCode.ashx"; //请求验证码的地址
HttpItem item1 = new HttpItem();
item1.URL = urlcode;
item1.Method = "get";
//item1.Cookie = result.Cookie;
item1.CookieCollection = result.CookieCollection;
item1.ResultCookieType = ResultCookieType.CookieCollection;
item1.ResultType = ResultType.Byte;
item1.Referer = url;
HttpResult result1 = http.GetHtml(item1);
cc.Add(result1.CookieCollection);
pictureBox1.Image = byteArrayToImage(result1.ResultByte); //显示验证码
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
string logurl = "http://[size=14.3999996185303px]xxxx.xxxx.cn/Admin/AdminLogin.aspx";
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmllogin);
string __EVENTTARGET = doc.GetElementbyId("__EVENTTARGET").GetAttributeValue("value", "");
string __EVENTARGUMENT = doc.GetElementbyId("__EVENTARGUMENT").GetAttributeValue("value", "");
string __VIEWSTATEGENERATOR = doc.GetElementbyId("__VIEWSTATEGENERATOR").GetAttributeValue("value", "");
string __EVENTVALIDATION = doc.GetElementbyId("__EVENTVALIDATION").GetAttributeValue("value", "");
string ctl00_ContentPlaceHolder1_UsernameTextBox = "slzb0122";// doc.GetElementbyId("ctl00_ContentPlaceHolder1_UsernameTextBox").GetAttributeValue("value", "");
string ctl00_ContentPlaceHolder1_PasswordTextBox = "slzb85816064";//doc.GetElementbyId("ctl00_ContentPlaceHolder1_PasswordTextBox").GetAttributeValue("value", "");
string ctl00_ContentPlaceHolder1_VerifyTextBox = textBox1.Text.Trim();//doc.GetElementbyId("ctl00_ContentPlaceHolder1_VerifyTextBox").GetAttributeValue("value", "");
string ctl00_ContentPlaceHolder1_LoginBtn = doc.GetElementbyId("ctl00_ContentPlaceHolder1_LoginBtn").GetAttributeValue("value", "");
HttpHelper http = new HttpHelper();
HttpItem item2 = new HttpItem();
item2.URL = logurl;
item2.Method = "post";
item2.CookieCollection = cc; //使用上个方法中的cookie 有两个
item2.ResultCookieType = ResultCookieType.CookieCollection;
item2.Postdata = string.Format("__EVENTTARGET={0}&__EVENTARGUMENT={1}&__VIEWSTATEGENERATOR={2}&__EVENTVALIDATION={3}&ctl00_ContentPlaceHolder1_UsernameTextBox={4}&ctl00_ContentPlaceHolder1_PasswordTextBox={5}&ctl00_ContentPlaceHolder1_VerifyTextBox={6}&ctl00_ContentPlaceHolder1_LoginBtn={7}"
, __EVENTTARGET, __EVENTARGUMENT, __VIEWSTATEGENERATOR, __EVENTVALIDATION, ctl00_ContentPlaceHolder1_UsernameTextBox, ctl00_ContentPlaceHolder1_PasswordTextBox, ctl00_ContentPlaceHolder1_VerifyTextBox, ctl00_ContentPlaceHolder1_LoginBtn);
HttpResult resultLog = http.GetHtml(item2);
string mainurl = "http://[size=14.3999996185303px]xxxx.xxxx.cn/Admin/Main.aspx";
HttpItem item3 = new HttpItem();
item3.URL = mainurl;
item3.Method = "get";
item3.CookieCollection = cc;//resultLog.CookieCollection;
item3.ResultCookieType = ResultCookieType.CookieCollection;
HttpResult mailresult = http.GetHtml(item3); //不能进入到Main.aspx
}
求大神支招。感谢
网站大概如此,登录到Main.aspx即可,有意者详细联系QQ232642397 |
|
|