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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 3935|回复: 2

[HttpHelper] 紧急求助!!!模拟登录,报用户名密码错误?

[复制链接]
发表于 2018-6-8 10:25:25 | 显示全部楼层 |阅读模式
微信图片_20180608102327.png 微信图片_20180608102334.png
请大家帮忙看看代码有什么问题么?
public partial class Form1 : Form
    {
        private String loginUrl = @"http://jkda.jxhfpc.gov.cn/";
        private String actionUrl = @"http://jkda.jxhfpc.gov.cn/login/userLogin.action";
        private String codeUrl = @"http://jkda.jxhfpc.gov.cn/login/imageCode.action";
        private HttpHelper http = new HttpHelper();
        private String cookie = null;
        public Form1()
        {
            InitializeComponent();
            Initialize();
        }
        private void Initialize()
        {
            HttpItem item = new HttpItem()
            {
                URL = loginUrl,
                Method = "get",//URL     可选项 默认为Get   
                ResultType = ResultType.String
            };
            HttpResult result = http.GetHtml(item);
            cookie = result.Cookie;
            item = new HttpItem()
            {
                URL = codeUrl,
                Method = "get",//URL     可选项 默认为Get  
                Cookie = cookie,
                ResultType = ResultType.Byte
            };
            Image img = http.GetImage(item);
            this.pictureBoxCode.Image = img;
            this.pictureBoxCode.Refresh();
        }
        private void buttonRefesh_Click(object sender, EventArgs e)
        {
            HttpItem item = new HttpItem()
            {
                URL = codeUrl,
                Method = "get",//URL     可选项 默认为Get  
                Cookie = cookie,
                ResultType = ResultType.Byte
            };
            Image img = http.GetImage(item);
            this.pictureBoxCode.Image = img;
            this.pictureBoxCode.Refresh();
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            String postData = string.Format("username={0}&password={1}&vercode={2}&online=on", this.textBoxUsername.Text.Trim(), this.textBoxPassword.Text.Trim(), this.textBoxVercode.Text);
            HttpItem item = new HttpItem()
            {
                URL = actionUrl,//URL     必需项   
                Accept = "*/*",
                UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
                Method = "post",//URL     可选项 默认为Get  
                Cookie = cookie,
                ContentType = "application/x-www-form-urlencoded; charset=UTF-8",//返回类型    可选项有默认值
                Postdata = postData,//Post要发送的数据
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            Console.Write(html);
            MessageBox.Show(html);
        }
    }



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2018-6-8 10:33:20 | 显示全部楼层
少两个参数的吧
token_key: 1d6672e001fd7812c39fdb0b9433b8bb
token_value: 45d62ee6db0542dba04deeb5fb5d21e7
 楼主| 发表于 2018-6-8 11:04:33 | 显示全部楼层
我试了一下,还是同样的结果。。。。。
public partial class Form1 : Form
    {
        private String loginUrl = @"http://jkda.jxhfpc.gov.cn/";
        private String actionUrl = @"http://jkda.jxhfpc.gov.cn/login/userLogin.action";
        private String codeUrl = @"http://jkda.jxhfpc.gov.cn/login/imageCode.action";
        private HttpHelper http = new HttpHelper();
        private String cookie = "JSESSIONID={0}; BIGipServerPool_jkda={1}";
        private String token_key= null;
        private String token_value = null;
        public Form1()
        {
            InitializeComponent();
            Initialize();
        }
        private void Initialize()
        {
            HttpItem item = new HttpItem()
            {
                URL = loginUrl,
                Method = "get",//URL     可选项 默认为Get   
                ResultType = ResultType.String
            };
            HttpResult result = http.GetHtml(item);
            String str = result.Cookie;
            String key = HttpHelper.GetBetweenHtml(result.Cookie, "JSESSIONID=", ";");
            String sid = HttpHelper.GetBetweenHtml(result.Cookie, "BIGipServerPool_jkda=", ";");
            cookie = string.Format(cookie, key, sid);
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(result.Html);
            token_key = doc.DocumentNode.SelectSingleNode("//input[@name='token_key']").Attributes["value"].Value;
            token_value = doc.DocumentNode.SelectSingleNode("//input[@name='token_value']").Attributes["value"].Value;            
            item = new HttpItem()
            {
                URL = codeUrl,
                Method = "get",//URL     可选项 默认为Get  
                Cookie = cookie,
                ResultType = ResultType.Byte
            };
            Image img = http.GetImage(item);
            this.pictureBoxCode.Image = img;
            this.pictureBoxCode.Refresh();
        }
        private void buttonRefesh_Click(object sender, EventArgs e)
        {
            HttpItem item = new HttpItem()
            {
                URL = codeUrl,
                Method = "get",//URL     可选项 默认为Get  
                Cookie = cookie,
                ResultType = ResultType.Byte
            };
            Image img = http.GetImage(item);
            this.pictureBoxCode.Image = img;
            this.pictureBoxCode.Refresh();
        }

        private void buttonLogin_Click(object sender, EventArgs e)
        {
            String postData = string.Format("token_key={0}&token_value={1}&username={2}&password={3}&vercode={4}&online=on", token_key, token_value, this.textBoxUsername.Text.Trim(), this.textBoxPassword.Text.Trim(), this.textBoxVercode.Text);
            HttpItem item = new HttpItem()
            {
                URL = actionUrl,//URL     必需项   
                Accept = "*/*",
                UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36",
                Method = "post",//URL     可选项 默认为Get  
                Cookie = cookie,
                ContentType = "application/x-www-form-urlencoded; charset=UTF-8",//返回类型    可选项有默认值
                Postdata = postData,//Post要发送的数据
            };
            //请求的返回值对象
            HttpResult result = http.GetHtml(item);
            //获取请请求的Html
            string html = result.Html;
            Console.Write(html);
            MessageBox.Show(html);
        }
    }
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-4-19 19:54

© 2014-2021

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