[C#] 纯文本查看 复制代码
/// <summary>
/// 获取验证码图片
/// </summary>
private void GetVerCode()
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.510376.com/login.php",
Accept = "text/html, application/xhtml+xml, */*",
Method = "get",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = Cookie,//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统 可选项有默认值
Referer = "http://www.510376.com/login.php",//来源URL 可选项
ResultType = ResultType.String,//返回数据类型,是Byte还是String
};
HttpResult result = http.GetHtml(item);
Cookie_A = result.Cookie;
txtHtml.Text = " 第一次访问时的Cookie:\n" + Cookie_A;
item = new HttpItem()
{
URL = "http://www.510376.com/tools/regcode.php?verify=08login&t=",
Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5",
Method = "get",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = Cookie_A,//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统 可选项有默认值
Referer = "http://www.510376.com/login.php",//来源URL 可选项
ResultType = ResultType.Byte,//返回数据类型,是Byte还是String
};
Image img = http.GetImage(item);
pictureBox1.Image = img;
result = http.GetHtml(item);
Cookie_A = result.Cookie;
//Cookie_A = "6QC_Q5gqrT_upload=1%2C2%2C3%2C4%2C5%2C6%2C7%2C8%2C9%2C10%2C11%2C12; menubox1=menubox1; 6QC__08_hash=ae2fc5670e3b9b447624d0da87ad84bf;"+HttpHelper.GetSmallCookie(Cookie_A);
//获取请求的Cookie
txtHtml.Text = txtHtml.Text+"\n获取验证码时的Cookie:\n" + Cookie_A;
}
[C#] 纯文本查看 复制代码
/// <summary>
/// 提交登录
/// </summary>
private void btnOK_Click(object sender, EventArgs e) //点击确定按钮事件
{
//万能框架对象
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = "http://www.510376.com/index.php?/ajax/check_login/username/%E4%BF%A1%E9%98%B3%E8%AF%9A%E4%BF%A1%E4%BA%8C%E6%89%8B%E8%BD%A6/password/a123456/regcode/" + txtCode.Text.Trim() + "/verify/08login/expires/604800/cmslogin/1/datatype/json/domain/www.510376.com&callback=jQuery1102033559174329472374_1532680542340&_=1532680542341",//URL 必需项
Method = "GET",//URL 可选项 默认为Get
Timeout = 100000,//连接超时时间 可选项默认为100000
ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
Cookie = Cookie_A,//字符串Cookie 可选项
UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0",//用户的浏览器类型,版本,操作系统 可选项有默认值
Accept = "text/html, application/xhtml+xml, */*",// 可选项有默认值
ContentType = "text/html",//返回类型 可选项有默认值
//ContentType = "application/x-www-form-urlencoded",
//ContentType = "application/json",
Referer = "http://www.510376.com/login.php",//来源URL 可选项
Postdata = "",//Post数据 可选项GET时不需要写
ResultType = ResultType.String,//返回数据类型,是Byte还是Strin
};
HttpResult result = http.GetHtml(item);
string html = result.Html;
string cookie = result.Cookie;
cookie = HttpHelper.GetSmallCookie(cookie);
txtHtml.Text = txtHtml.Text + "\n" + "点击登录时的Cookie:\n" + cookie + "\n" + "得到的提示:\n" + html;
// MessageBox.Show("登录成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
//以下开始显示主窗体 并关闭登录窗体
//this.DialogResult = DialogResult.OK;
//this.Close();
}