http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3389|回复: 3

[HttpHelper] 带验证码的Ajax登录,提示验证码不正确

[复制链接]
发表于 2018-7-26 17:10:09 | 显示全部楼层 |阅读模式
qq.png

URL地址是:
http://www.网址.com/index.php?/ajax/check_login/username/这里是用户名/password/这里是密码/regcode/7034/verify/08login/expires/604800/cmslogin/1/datatype/json/domain/www.网址.com&callback=jQuery110208565981670715967_1532587707493&_=1532587707494

[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CsharpHttpHelper;
using System.IO;
using CsharpHttpHelper.Enum;
using System.Net;

namespace TestDock
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
            DateTime dt = DateTime.Now;
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
            int curTime= (int)(dt - startTime).TotalSeconds; 
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.510376.com/tools/regcode.php?verify=08login&t=",
                Method = "get",//URL     可选项 默认为Get   
            };
            Image img = http.GetImage(item);
            pictureBox1.Image = img;
            HttpResult result = http.GetHtml(item);
            //获取请求的Cookie
            Cookies = result.Cookie;
        }

        private void btnExit_Click(object sender, EventArgs e)    //单击关闭按钮事件
        {
            Application.Exit();
        }
        string Cookies = string.Empty;
        private void btnOK_Click(object sender, EventArgs e)  //点击确定按钮事件
        {
            string u = txtUser.Text.Trim();
            string p = txtPass.Text.Trim();
            //万能框架对象

            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = "http://www.510376.com/index.php?/ajax/check_login/username/这里是用户名/password/这里是密码/regcode/7034/verify/08login/expires/604800/cmslogin/1/datatype/json/domain/www.510376.com&callback=jQuery110208565981670715967_1532587707493&_=1532587707494",//URL     必需项
                Method = "GET",//URL     可选项 默认为Get
                //Encoding = "System.Text.DBCSCodePageEncoding",//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
                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",//用户的浏览器类型,版本,操作系统     可选项有默认值
                Accept = "text/html, application/xhtml+xml, */*",//    可选项有默认值
                ContentType = "text/html",//返回类型    可选项有默认值
                Referer = "http://www.510376.com/login.php",//来源URL     可选项
                Allowautoredirect = false,//是否根据301跳转     可选项
                AutoRedirectCookie = false,//是否自动处理Cookie     可选项
                ResultType = ResultType.String,//返回数据类型,是Byte还是String
            };
            MessageBox.Show(txtCode.Text.Trim());
            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            string cookie = result.Cookie;
            txtHtml.Text = html ;

        }
        /// <summary>
        /// 字节数组生成图片
        /// </summary>
        /// <param name="Bytes">字节数组</param>
        /// <returns>图片</returns>
        private Image byteArrayToImage(byte[] Bytes)
        {
            MemoryStream ms = new MemoryStream(Bytes);
            return Bitmap.FromStream(ms, true);
        }

    }
}





1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2018-7-27 09:59:09 | 显示全部楼层
看情况应该是没带上cookie
 楼主| 发表于 2018-7-27 15:18:39 | 显示全部楼层
合久必婚 发表于 2018-7-27 09:59
看情况应该是没带上cookie

参考这个贴子,http://www.sufeinet.com/thread-13273-1-8.html 修改了申明对象的位置(HttpHelper http = new HttpHelper();),解决了传递Cookie时变量不存在的问题。
但对比了两次请求的cookie,不一样。
1.png


 楼主| 发表于 2018-8-6 18:47:25 | 显示全部楼层
这个问题解决了,主要是
Image img = http.GetImage(item);
            pictureBox1.Image = img;
这一块代码的问题,其中http.GetImage(item)的时候,多请求了一次验证码
其调用的ByteToImage函数里的代码:
MemoryStream ms = new MemoryStream(b);
return Bitmap.FromStream(ms, true);
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-19 11:18

© 2014-2021

快速回复 返回顶部 返回列表