|
带验证码登陆问题,先前发过一贴,由于存在一些问题,现在好了,因此再次发帖
我的思路是首先访问登陆页面,取得cookie,然后带着这个cookie再去访问验证码的页面,取得验证码图像显示在界面上,
然后用户自己手动输入,然后再继续带着这个cookie(带着验证码的图像的页面的cookie也试过)post登陆,一直
提示“本次请求并未返回任何数据”,不知何原因,小弟刚刚接触这个,还请给位帮忙看看是不是哪里弄错了,@站长苏飞
下面附上我的关键代码和工程文件
下面是获取验证码代码- string code_cookie;//保存cookie
-
- private void DOCaiJi_88city(object obj)
- {
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = "http://xxxx.com/appg/login.php",//URL 必需项
- Method = "get",//URL 可选项 默认为Get
- IsToLower = false,//得到的HTML代码是否转成小写 可选项默认转小写
- Cookie = "",//字符串Cookie 可选项
- Referer = "",//来源URL 可选项
- Postdata = "",//Post数据 可选项GET时不需要写
- Timeout = 100000,//连接超时时间 可选项默认为100000
- ReadWriteTimeout = 30000,//写入Post数据超时时间 可选项默认为30000
- UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
- ContentType = "text/html",//返回类型 可选项有默认值
- Allowautoredirect = false,//是否根据301跳转 可选项
- };
- HttpResult result = http.GetHtml(item);
-
- code_cookie = result.Cookie;
- item.URL = "http://g818city.com/appg/draw_gd.php";
- item.Accept = "image/png, image/svg+xml, image/*;q=0.8, */*;q=0.5";
- item.Encoding = null;
- item.ResultType = ResultType.Byte;
- result = http.GetHtml(item);
-
- pictureBox1.Image = byteArrayToImage(result.ResultByte);
- this.BeginInvoke(new MethodInvoker(delegate()
- {
- this.button4.Enabled = true;
- }));
- }
复制代码 下面是post登陆的代码
- private Image byteArrayToImage(byte[] Bytes)
- {
- MemoryStream ms = new MemoryStream(Bytes);
- Image outputImg = Image.FromStream(ms);
- return outputImg;
- }
- private void button7_Click(object sender, EventArgs e)
- {
- HttpHelper http = new HttpHelper();
- string fr_gdcode = textBox1.Text.Trim();
- HttpItem item = new HttpItem()
- {
- URL = "http://xxx.com/appg/login.php?",//URL 必需项
- Method = "post",//URL 可选项 默认为Get
- Referer = "http://g818city.com/appg/login.php?lang=",//来源URL 可选项
- Postdata = "fr_username=hu2828&fr_password=huqiliang131&fr_gdcode=" + fr_gdcode + "&language=simplified&fr_language=simplified&fr_companycode=a2700&fr_querycheck=http%3A%2F%2Fg818city.com%2Fappg%2Flogin.php",//Post数据 可选项GET时不需要写
- UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)",//用户的浏览器类型,版本,操作系统 可选项有默认值
- ContentType = "application/x-www-form-urlencoded",//返回类型 可选项有默认值
- };
-
- code_cookie = code_cookie.Replace("path=/,", "").Replace(";path=/", "");
- item.Cookie = code_cookie;
- HttpResult result = http.GetHtml(item);
- string html2 = result.Html;
- item.URL = "http://g818city.com/appg/login.php?";
- item.Cookie = result.Cookie;
- result = http.GetHtml(item);
- string html = result.Html;
- StreamWriter sw = new StreamWriter("data.txt", true, Encoding.GetEncoding("gb2312"));
- sw.WriteLine(html2+html + code_cookie);
- sw.Close();
- MessageBox.Show("完成!");
- }
复制代码 |
-
-
ylc.rar
277.65 KB, 下载次数: 206, 下载积分: 金钱 -1
工程文件
|