12306.cn网站自动登录器源代码
2012-02-06 22:33
435 查看
去年过年放假的时候写了一个12306.cn网站的自动登录器,刚好那时候放假了,所以没把源代码放出来,现在将代码发出来,由于编写得比较仓促(从放假的下午19:00左右到晚上到00:00左右),很多细节问题考虑不是很全面,如断网的情况未考虑,界面比较简单,错误之处请大家批评指正.注意:本程序基于.netframework4.0编写,UI使用WPF源代码下载地址1:http://115.com/file/e7l5t4uw
源代码下载地址2:http://files.cnblogs.com/loyldg/AutoLogin12306_src.rar其实自动登录比较简单,就是发送一个http请求并传递参数,然后对响应的结果进行分析处理.下面我列出需要注意的几个问题.1.发送http请求时,需要对传递的参数进行Url编码(使用HttpUtility.UrlEncode方法)
2.刷新验证码后,需要将当前的Cookie信息替换(刷新验证码后会产生的新的Cookie,使用此Cookie替换原有Cookie信息即可)
3.处理Https证书问题,直接信任所有证书即可.
源代码下载地址2:
2.刷新验证码后,需要将当前的Cookie信息替换(刷新验证码后会产生的新的Cookie,使用此Cookie替换原有Cookie信息即可)
3.处理Https证书问题,直接信任所有证书即可.
privatevoidSetCertificatePolicy()
{
ServicePointManager.ServerCertificateValidationCallback
+=RemoteCertificateValidate;
}privateboolRemoteCertificateValidate(
objectsender,X509Certificatecert,
X509Chainchain,SslPolicyErrorserror)
{
returntrue;
}
4.登录成功后,打开IE浏览器,并将登录成功后的Cookie信息传递到IE浏览器,这里需要使用到InternetSetCookie方法,该方法在wininet.dll中.
关键代码如下:
[DllImport("wininet.dll",CharSet=CharSet.Auto,SetLastError=true)]
publicstaticexternboolInternetSetCookie(stringlpszUrl,stringlbszCookieName,stringlpszCookieData);privatevoidOpenIEWithCookie(CookieCollectioncookies,stringurl)
{
stringexpires="expires=Sun,22-Feb-209900:00:00GMT";
foreach(Cookieitemincookies)
{
boolisSuccess=InternetSetCookie(item.Path,item.Name,string.Format("{0};{1}",item.Value,expires));
if(!isSuccess)
{
interrorCode=Marshal.GetLastWin32Error();
App.Messenger.NotifyColleagues(Msg.APPEND_MESSAGE,"setcookieerror,errorCode:"+errorCode);
}
}
stringieFilePath=Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)+"\\InternetExplorer\\iexplore.exe";
if(File.Exists(ieFilePath))
{
System.Diagnostics.Process.Start(ieFilePath,url);
App.Messenger.NotifyColleagues(Msg.APPEND_MESSAGE,"OpenUrl:"+url);
}
else
{
App.Messenger.NotifyColleagues(Msg.APPEND_MESSAGE,"未找到IE浏览器");
}
}
相关文章推荐
- 再次绕过旷世奇葩12306.cn网站BUG,自动登录网站,自动搜索余票
- JAVA通过Session和Cookie实现网站自动登录的技术
- 自动化测试 (一) 12306火车票网站自动登录工具
- 有关采用Filter:实现网站自动登录功能模块
- python3.2 自动登录网站
- c# 实现网页上用户自动登陆|asp.net 模拟网站登录
- android 怎样实现从文本框获得用户名和密码,自动登录网站?
- (转)Web自动化测试之12306火车票网站自动登录工具
- IIS绑定Active Directory账号自动登录网站的方法
- 网站的下次自动登录功能的实现方法
- 一个网站登录,然后下载网页源代码和文件的代码
- 自动登录网站表单(双击即可进入网站无需输入用户密码)
- python网络爬虫之使用scrapy自动登录网站
- 自动登录http://www.netyi.net/网站的工具
- Python 自动登录网站(处理Cookie)
- Web自动化测试之12306火车票网站自动登录工具 [转]
- 自动登录CSDN网站,并回复帖子
- C#自动登录网站(一)----WebBrowser
- TC脚本开发-梦幻诛仙自动登录思路梳理及源代码
- Python自动登录带密码的网站