模拟学信网登录,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 ...
随机推荐
- javascript中的关键字和保留字
javascript中关键字的问题,将名称替换了下,确实就没有问题了.现在将它的关键字和保留字贴出来,便于日后查看和避免在次出现类似的问题. 1 关键字breakcasecatchcontinuede ...
- 关于ecshop中jquery与js冲突解决的方案
ECShop把AJAX事件和JSON解析的模块放在common/transport.js之中,可以说它也有自己封装的一套工具,这其实是很正常的. 但恰恰的,在封装JSON各种方法的同时对objec ...
- poj 1236 Network of Schools
题目描述:有一些学校连接到一个计算机网络.这些学校之间达成了一个协议:每个学校维护着一个学校列表,它向学校列表中的学校发布软件.注意,如果学校B在学校A的列表中,则A不一定在B的列表中.任务A:计算为 ...
- 查看buffer cache命中率
SQL> select name,value from v$sysstat where name in('db block gets','consistent gets','physical r ...
- JazzyViewPager开源项目的简析及使用
JazzyViewPager是一个重写的ViewPager,能是ViewPager滑动起来更加的炫酷. 开源地址:https://github.com/jfeinstein10/JazzyViewPa ...
- [原创]C语言利用pcre正则表达式库
C语言使用正则表达式,可以利用pcre库,这个比较不错的哦. 在使用过程中,利用python进行测试正则表达式是否OK,后发现出现了问题.如下所示: regex.c:11:18: warning: u ...
- 22、TTS技术
Android对TTS技术的支持 Android 1.6开始支持TTS(Text To Speech)技术,通过该技术可以将文本转换成语音. TTS技术的核心是android.speech.tts.T ...
- Matlab编程实例(4) 相位角与相关系数曲线
%相位角与相关系数曲线 close all; clear all; Samp1=200; %设置信号的采样精度 Samp2=200; %设置相位角p分割精度 A=10;%信号幅值 w=1;%信号角 ...
- Spring 定时任务的实现<转>
本人暂时用到的实现定时任务的方式有2种 一.注解方式实现,简单方便 1:在applicationContext.xml中加入下面的配置, 这是spring的组件扫描,保证含有定时任务的类,能被spri ...
- Cadence关闭StartPage的方法
Cadence 16.5开始,打开原理图工具 Orcad Capture 时,总是会弹出startpage 页面,关闭它的方法: 解决方法如下: (1) View---Toolbar----Comma ...