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

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

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

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

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

查看: 6306|回复: 12

[求助] 12306登录

[复制链接]
发表于 2014-5-20 22:27:27 | 显示全部楼层 |阅读模式


   我使用你这个类库,模拟登录12306的网站,能正确获取到验证码,然后POST登录时老是返回如下信息

{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{},"messages":["网络忙,请刷新重试!"],"validateMessages":{}}


模拟登录的代码如下

string m_MainUrl = "https://kyfw.12306.cn/otn/login/loginAysnSuggest";
                string data = "loginUserDTO.user_name=" + strName + "&userDTO.password=" + strPsWord + "&randCode=" + RandCode;

                HttpHelper http = new HttpHelper();
                HttpItem item = new HttpItem()
                {
                    URL = m_MainUrl,//URL     必需项   
                    Method = "POST",//URL     可选项 默认为Get
                    Postdata = data,//Post数据     可选项GET时不需要写   
                    Cookie=p_Cookies,    //这个我在获取验证码时拿到保存,这时再传入
                    ResultType = ResultType.Byte
                };
                HttpResult result = http.GetHtml(item);
                string m_LoginReturnCode = result.Html;



不知道是什么原因,请各位指点下。
谢谢



1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2014-5-20 22:30:32 | 显示全部楼层
头信息不对
发表于 2014-5-20 22:32:30 | 显示全部楼层
应该发程序上来
 楼主| 发表于 2014-5-21 13:56:56 | 显示全部楼层



那请问你指的缺少head,

是Request header 还是response header呢?
QQ图片20140521135529.jpg
发表于 2014-5-21 14:06:04 | 显示全部楼层
  ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值   

加上这个试试
 楼主| 发表于 2014-5-21 14:18:19 | 显示全部楼层
站长苏飞 发表于 2014-5-21 14:06
ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值   

加上这个试试

好的,谢谢版主。晚上我回去试下。

有问题再向您请教
 楼主| 发表于 2014-5-21 20:28:12 | 显示全部楼层
站长苏飞 发表于 2014-5-21 14:06
ContentType = "application/x-www-form-urlencoded",//返回类型    可选项有默认值   

加上这个试试

加到这个后,一直提示验证码错误。

但是我验证码是对的。
发表于 2014-5-21 20:59:16 | 显示全部楼层
获取验证码带cookie了吗
 楼主| 发表于 2014-5-21 21:04:31 | 显示全部楼层
站长苏飞 发表于 2014-5-21 20:59
获取验证码带cookie了吗


                HttpItem item = new HttpItem()
                {
                    URL = "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew.do?module=login&rand=sjrand",//URL     必需项   
                    Method = "get",//URL     可选项 默认为Get
                    ResultType = ResultType.Byte
                };
                HttpResult result = http.GetHtml(item);
                p_RequestCookies = result.Cookie;

上面这个获取验证码的,将COOKIE保存到p_RequestCookies
然后接着调用登录,代码如下
string m_MainUrl = "https://kyfw.12306.cn/otn/login/loginAysnSuggest";
                string m_PostData = "loginUserDTO.user_name=" + strName + "&userDTO.password=" + strPsWord + "&randCode=" + RandCode;

                HttpItem item = new HttpItem()
                {
                    URL = m_MainUrl,   
                    Method = "post",
                    Postdata = m_PostData,
                    Cookie=p_RequestCookies,
                    KeepAlive=true,
                    ContentType="application/x-www-form-urlencoded",
                    UserAgent="Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)",
                    ResultType = ResultType.Byte
                };
                HttpResult result = http.GetHtml(item);

                string m_LoginReturnCode = result.Html;

 楼主| 发表于 2014-5-21 22:33:39 | 显示全部楼层
站长苏飞 发表于 2014-5-21 20:59
获取验证码带cookie了吗

现在我发现了一个问题,获取验证码后
HttpResult result = http.GetHtml(item);
result.CookieCollection 的里面的COOKIE是0,这是否是个BUG还是我写法有问题呢
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

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

GMT+8, 2024-5-17 12:47

© 2014-2021

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