|
楼主 |
发表于 2015-8-21 22:08:05
|
显示全部楼层
完整的代码:
namespace LoginNyDus
{
public partial class frmMain : Form
{
#region 变量定义及界面初始化
HttpHelper http = new HttpHelper();
HttpItem item = null;
HttpResult result = null;
string Cookies = "";
string retCode = "";
string dCode = "";
public frmMain()
{
InitializeComponent();
}
#endregion
private void frmMain_Load(object sender, EventArgs e)
{
GetVerCode();//获取验证码
}
private void button1_Click(object sender, EventArgs e)
{
item = new HttpItem()
{
URL = "http://www.nydus2015.info/login?callback=/loginbbs",
Method = "POST",
Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*",
Referer = "http://www.nydus2015.info/login?callback=/loginbbs",
UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)",
Postdata = string.Format("username={0}&password={1}&code={2}", txtUser.Text.Trim(), txtPass.Text.Trim(),txtVerCode.Text.Trim()),
Cookie = Cookies
};
result = http.GetHtml(item);
retCode = result.Html;
}
private void GetVerCode()
{
/* 原网站中验证码图片的HTML
* <img src="/code?d=745090" id="codeimg" alt="验证码" style="vertical-align:top;cursor:pointer;margin-top:padding-bottom:10px;"
* title="点击刷新验证码" onclick="this.src='/code?d='+Math.random();">
*
* <img src="/code?d=0.31528944824822247" id="codeimg" alt="验证码" style="vertical-align:top;cursor:pointer;margin-top:padding-bottom:10px;" title="点击刷新验证码" onclick="this.src='/code?d='+Math.random();">
*/
item = new HttpItem()
{
URL = "http://www.nydus2015.info/login?callback=/loginbbs",
Method = "GET",
Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*",
UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"
};
result = http.GetHtml(item);
Cookies = result.Cookie;
retCode = result.Html;
dCode = Utilities.GetMidStr(retCode, @"code?d=", "\"");
item = new HttpItem()
{
URL = "http://www.nydus2015.info/code?d=" + dCode,
Method = "GET",
Accept = "*/*",
Referer = "http://www.nydus2015.info/",
ResultType = ResultType.Byte,
Cookie = Cookies
};
result = http.GetHtml(item);
pictureBox1.Image = Utilities.GetImageFromByte(result.ResultByte);
}
}
} |
|