模拟学信网登录,Cookie 序列化,在反序列化之后不能用的问题
昨天和今天在模拟学信网登录,然后抓取用户的信息数据的时候发现一直登录不成功,
登录页面,https://account.chsi.com.cn/passport/login?service=http%3A%2F%2Fmy.chsi.com.cn%2Farchive%2Fj_spring_cas_security_check

打开登录页面,发现就注入cookie了,然后自己也要模拟一个get请求,然后获取到cookie,
AccountModel accmodel = new AccountModel();
accmodel.username = "账号";
accmodel.password = "密码";
accmodel._eventId = "submit";
accmodel.submit = "登 录";
HttpHelper httphelper = new HttpHelper();
string strhtmlresult = httphelper.HttpGet(LoginIndexURL);
Regex regexlt = new Regex("<input type=\"hidden\" name=\"lt\" value=\"(?<hiddenlt>[^\"]*?)\"");
///携带验证标识
if (regexlt.IsMatch(strhtmlresult))
{
accmodel.lt = regexlt.Match(strhtmlresult).Groups["hiddenlt"].Value;
}
//获取cookie
List<Cookie> cookielist = new List<Cookie>();
foreach (Cookie cookie in httphelper.reponsecookie)
{
cookielist.Add(cookie);
}
httphelper.cookielist=cookielist;
#region 开始模拟cookie 请求
//model转换为dic,顺便把为空为null的值删掉
IDictionary<string, string> dicaccmodle = ModelUtil<AccountModel>.CreateDataALLdic_String(accmodel,true);
//HttpHelper httphelper = new HttpHelper();
//注入cookie
foreach (Cookie cookie in cookielist)
{
//cookielist.Add(new CookieModel() { Domain = cookie.Domain, Name = cookie.Name, Path = cookie.Path, Value = cookie.Value });
httphelper.requestcookie.Add(cookie);
}
strhtmlresult = httphelper.HttpPost(LoginIndexURL, SoleFupaySignature.GetSignContentbEncode_NoSort(dicaccmodle), LoginIndexURL);
Regex regexSchoolInformation = new Regex("a href=\"(?<SchoolInformationURL>[^\"]*?)\">学籍信息");
if (regexSchoolInformation.IsMatch(strhtmlresult))
{
string strSchoolInformationURL = regexSchoolInformation.Match(strhtmlresult).Groups["SchoolInformationURL"].Value;
string strhtmlSchoolInformation = httphelper.HttpGet(strSchoolInformationURL);
return new RedirectResult("/home/LoginSucess");
}
else
{
///携带验证标识
if (regexlt.IsMatch(strhtmlresult))
{
accmodel.lt = regexlt.Match(strhtmlresult).Groups["hiddenlt"].Value;
}
Regex regexcaptcha = new Regex("<input type=\"text\" class='input_text' id='captcha'");
///是否出现验证码
if (regexcaptcha.IsMatch(strhtmlresult))
{
ViewBag.captcha = true;
}
}
#endregion
这样发现成功了
而把get和post分开放到另外一个方法中,用一个序列化的cookie在反序列化就不行了。
AccountModel accmodel = new AccountModel();
accmodel.username = "账号";
accmodel.password = "密码";
accmodel._eventId = "submit";
accmodel.submit = "登 录";
HttpHelper httphelper = new HttpHelper();
string strhtmlresult = httphelper.HttpGet(LoginIndexURL);
Regex regexlt = new Regex("<input type=\"hidden\" name=\"lt\" value=\"(?<hiddenlt>[^\"]*?)\"");
///携带验证标识
if (regexlt.IsMatch(strhtmlresult))
{
accmodel.lt = regexlt.Match(strhtmlresult).Groups["hiddenlt"].Value;
}
//获取cookie
List<Cookie> cookielist = new List<Cookie>();
foreach (Cookie cookie in httphelper.reponsecookie)
{
cookielist.Add(cookie);
}
httphelper.cookielist=cookielist;
Login1(accmodel, Newtonsoft.Json.JsonConvert.SerializeObject(cookielist));
}
public void Login1(AccountModel accmodel, string strcookielist)
{
List<Cookie> cookielist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Cookie>>(strcookielist);
IDictionary<string, string> dicaccmodle = ModelUtil<AccountModel>.CreateDataALLdic_String(accmodel, true);
HttpHelper httphelper = new HttpHelper();// Newtonsoft.Json.JsonConvert.DeserializeObject<HttpHelper>(strhttphelper);
foreach (Cookie cookie in cookielist)
{
httphelper.requestcookie.Add(cookie);
}
string strhtmlresult = httphelper.HttpPost(LoginIndexURL, SoleFupaySignature.GetSignContentbEncode_NoSort(dicaccmodle), LoginIndexURL);
}

发现失败了, 后面自己想了下,可能由于cookie序列化后不允许传递给另外一个对象,所以失败了,然后就在根据原来的cookie,然后new 一个,传递给list
把Login1 换成下面的就可以了。
public void Login1(AccountModel accmodel, string strcookielist)
{
List<Cookie> cookielist = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Cookie>>(strcookielist);
IDictionary<string, string> dicaccmodle = ModelUtil<AccountModel>.CreateDataALLdic_String(accmodel, true);
HttpHelper httphelper = new HttpHelper();// Newtonsoft.Json.JsonConvert.DeserializeObject<HttpHelper>(strhttphelper);
foreach (Cookie cookie in cookielist)
{
Cookie newcookie = new Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain);
newcookie.Secure = true;
newcookie.HttpOnly = true;
httphelper.requestcookie.Add(newcookie);
}
string strhtmlresult = httphelper.HttpPost(LoginIndexURL, SoleFupaySignature.GetSignContentbEncode_NoSort(dicaccmodle), LoginIndexURL);
}
然后这个是部署在服务器上面的,如果请求多的话会出现验证码,然后这样登录,如果去失败验证码。
模拟学信网登录,Cookie 序列化,在反序列化之后不能用的问题的更多相关文章
- java okhhtp下载学信网学籍信息
学信网的登录有验证码,是那种计算数字或者汉字识别的,很难识别.最近连学籍信息和学历信息也换成图片了,常规的正则 css xpath都不能使. 下载图片,需要先登录,获取登陆后的cookie和学籍信息的 ...
- 学信网改绑手机号码,但是忘记了老号码怎么办?利用node.js + puppeteer 跑脚本实现改绑手机号
最近登录学信网发现自己学信网上绑定的手机号码不是目前自己使用的手机号码,于是想改绑手机号,但是发现不记得之前的手机号码了: 于是百度各种方法都无济于事:也不想重新注册账号,最后看见一篇文章通过Pyth ...
- WebAPI调用笔记 ASP.NET CORE 学习之自定义异常处理 MySQL数据库查询优化建议 .NET操作XML文件之泛型集合的序列化与反序列化 Asp.Net Core 轻松学-多线程之Task快速上手 Asp.Net Core 轻松学-多线程之Task(补充)
WebAPI调用笔记 前言 即时通信项目中初次调用OA接口遇到了一些问题,因为本人从业后几乎一直做CS端项目,一个简单的WebAPI调用居然浪费了不少时间,特此记录. 接口描述 首先说明一下,基于 ...
- 模拟登陆115网盘(MFC版)
[cpp] view plain copy // 模拟登陆115网盘 #include <afxinet.h> // 包含相关的头文件 /* 用抓包工具抓包可得到需要提交的数据,然后模拟提 ...
- c#获取新浪微博登录cookie
用新浪微博api收集数据有诸多限制,每小时只能调用官方api函数150次,认证也很麻烦.因此想通过爬网页的方式来收集数据.访问新浪微博用户网页首先需要登录,登录获取cookie后可直接获取网页数据,无 ...
- SpringBoot + Spring Security 学习笔记(五)实现短信验证码+登录功能
在 Spring Security 中基于表单的认证模式,默认就是密码帐号登录认证,那么对于短信验证码+登录的方式,Spring Security 没有现成的接口可以使用,所以需要自己的封装一个类似的 ...
- Spring Security构建Rest服务-1203-Spring Security OAuth开发APP认证框架之短信验证码登录
浏览器模式下验证码存储策略 浏览器模式下,生成的短信验证码或者图形验证码是存在session里的,用户接收到验证码后携带过来做校验. APP模式下验证码存储策略 在app场景下里是没有cookie信息 ...
- Spring Security构建Rest服务-0702-短信验证码登录
先来看下 Spring Security密码登录大概流程,模拟这个流程,开发短信登录流程 1,密码登录请求发送给过滤器 UsernamePasswordAuthenticationFilter 2,过 ...
- springboot +spring security4 自定义手机号码+短信验证码登录
spring security 默认登录方式都是用户名+密码登录,项目中使用手机+ 短信验证码登录, 没办法,只能实现修改: 需要修改的地方: 1 .自定义 AuthenticationProvide ...
随机推荐
- 函数get_table_share
得到一个table_share 1)先从table_def_cache中查找, 如果有, 直接返回 2)如果没有找到, 为table_share分配内存,初始化,打开.frm文件,并将share ...
- JAVA将Excel中的报表导出为图片格式(三)换一种实现
上一篇介绍了使用Java的Robot机器人实现截图,然后将剪贴板上的数据流生成PNG图片 但是经过博主的不断测试,在完全依赖远程桌面的没有终端显示器的服务器上 使用截图方式是不可行的,因为一旦使用了远 ...
- sql server删除数据后空间无变化处理方法
删除数据库表 第一步: 执行 delete from doc.115sou.com #删除数据,执行效率低 drop table doc.115sou.com #删除表 ...
- Jquery 弹出提示框输入插件 apprise 修改中文按钮以及使用说明
apprise的使用非常简单,引入js脚本和css <script type="text/javascript" src="/js/apprise-1.5.fu ...
- Java [Leetcode 328]Odd Even Linked List
题目描述: Given a singly linked list, group all odd nodes together followed by the even nodes. Please no ...
- jquery插件——日历控件
今天在网上有看到一个jquery插件——日历控件,不过之前也在柯乐义的网站上看到了(http://keleyi.com/ 推荐下) 这个插件看着比较大气,所以干脆也分享下,以后自己也好用一点儿 1.页 ...
- MySQL基础之第13章 MySQL函数
13.1.数学函数 随机数可能会用到,其他基本无视. 13.2.字符串函数 重点CONCAT(S1,S2….) 13.3.日期和时间函数 一.MySQL 获得当前日期时间 函数 1.1 获得当前日期+ ...
- HDU 5734 Acperience
Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- Druid连接池简单入门
偶尔的机会解释Druid连接池,后起之秀,但是评价不错,另外由于是阿里淘宝使用过的所以还是蛮看好的. 1.jar包依赖--Druid依赖代码 <dependency> <groupI ...
- Hadoop序列化
遗留问题: Hadoop序列化可以复用对象,是在哪里复用的? 介绍Hadoop序列化机制 Hadoop序列化机制详解 Hadoop序列化的核心 Hadoop序列化的比较接口 ObjectWrita ...