模拟艺龙旅游网登录,供大家参考,具体内容如下
想模拟登录,首先整理一下流程
1.通过360浏览器(IE,火狐等等)F12开发人员工具抓到相关数据
2.获取验证码(拿到cookie),登录时也需要使用
3.登录
F12调出开发人员工具,输入用户名,密码登录,看我们抓到了什么信息。
Request URL:这个就是登录请求的url
https://secure.elong.com/passport/ajax/elongLogin
方式POST
Form Data:这个是我们要POST传输的数据:
userName=xzdylyh&passwd=12313&validateCode=验证码&rememberMe=false
其它一些重要信息在Request Headers中
*****************************************************************
我使用C# 设计的winform界面
复制代码
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Web; using System.Net; using System.IO; using System.Data; namespace HTTPHELPER { public class ELOGN_LOGIN { public static CookieContainer container = null; //存储验证码cookie #region 登录 public string requestM(string uName,string passwd,string vaildate) { HttpWebRequest request = null; HttpWebResponse response = null; try { request = (HttpWebRequest)HttpWebRequest.Create("https://secure.elong.com/passport/ajax/elongLogin"); request.Method = "Post"; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36"; request.AllowAutoRedirect = true; request.CookieContainer = container;//获取验证码时候获取到的cookie会附加在这个容器里面 request.KeepAlive = true;//建立持久性连接 //整数据 string postData = string.Format("userName={0}&passwd={1}&validateCode={2}&rememberMe=true", uName, passwd, vaildate); ASCIIEncoding encoding = new ASCIIEncoding(); byte[] bytepostData = encoding.GetBytes(postData); request.ContentLength = bytepostData.Length; //发送数据 using结束代码段释放 using (Stream requestStm = request.GetRequestStream()) { requestStm.Write(bytepostData, 0, bytepostData.Length); } //响应 response = (HttpWebResponse)request.GetResponse(); string text = string.Empty; using (Stream responseStm = response.GetResponseStream()) { StreamReader redStm = new StreamReader(responseStm, Encoding.UTF8); text = redStm.ReadToEnd(); } return text; } catch (Exception ex) { var msg = ex.Message; return msg; } } #endregion #region 获取验证码 public Stream getCodeStream(string codeUrl) { //验证码请求 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(codeUrl); request.Method = "GET"; request.ContentType = "application/x-www-form-urlencoded"; request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0.1) Gecko/20100101 Firefox/5.0.1"; request.Accept = "image/webp,*/*;q=0.8"; request.CookieContainer = new CookieContainer();//!Very Important.!!! container = request.CookieContainer; var c = request.CookieContainer.GetCookies(request.RequestUri); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); response.Cookies = container.GetCookies(request.RequestUri); Stream stream = response.GetResponseStream(); return stream; } } #endregion }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using HTTPHELPER; namespace WindowsFormsApplication8 { public partial class ELONG_LOGIN_FORM : Form { public ELONG_LOGIN_FORM() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { ELOGN_LOGIN elongLogin = new ELOGN_LOGIN(); var rmsg = elongLogin.requestM(txtuserName.Text,txtPassword.Text,txtVaildata.Text); MessageBox.Show(rmsg); } private void ELONG_LOGIN_FORM_Load(object sender, EventArgs e) { ReflshPicImage();//更新验证码 } //更新验证码 public void ReflshPicImage() { string codeUrl = "https://secure.elong.com/passport/getValidateCode"; ELOGN_LOGIN agent = new ELOGN_LOGIN(); Stream stmImage = agent.getCodeStream(codeUrl); picValidate.Image = Image.FromStream(stmImage); } private void btnReValidate_Click(object sender, EventArgs e) { ReflshPicImage();//更新验证码 } private void picValidate_Click(object sender, EventArgs e) { ReflshPicImage();//更新验证码 } } }
最后执行效果,登录的session已经成功返回。
本文向大家介绍C#中HttpWebRequest、WebClient、HttpClient的使用详解,包括了C#中HttpWebRequest、WebClient、HttpClient的使用详解的使用技巧和注意事项,需要的朋友参考一下 HttpWebRequest: 命名空间: System.Net,这是.NET创建者最初开发用于使用HTTP请求的标准类。使用HttpWebRequest可以让开发
由于以下错误消息,我无法使用WebRequest连接到HTTPS服务器(TLS 1.3): 请求被中止:无法创建SSL/TLS安全通道。 以前的TLS版本是1.2,使用下面的代码,我可以正确获取页面,但当页面ssl升级到TLS 1.3时,我出现了错误,并且我找不到任何解决方案: 事实上,我认为应该是这样的: 但是没有。
本文向大家介绍使用C#发送Http请求实现模拟登陆实例,包括了使用C#发送Http请求实现模拟登陆实例的使用技巧和注意事项,需要的朋友参考一下 模拟登陆的原理很简单,就是发送一个Http 请求服务器获得响应,然后客户端获取到cookie即可实现模拟登陆,比如一些抢票软件的原理无非也是这样模拟客户端的cookie 然后发送请求去抢票,然后12306 本文将演示如何用C# 来实现模拟登陆的,推荐一款工
本文向大家介绍Python使用装饰器模拟用户登陆验证功能示例,包括了Python使用装饰器模拟用户登陆验证功能示例的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了Python使用装饰器模拟用户登陆验证功能。分享给大家供大家参考,具体如下: 运行结果: 更多关于Python相关内容感兴趣的读者可查看本站专题:《Python数据结构与算法教程》、《Python编码操作技巧总结》、《Python
问题内容: 我有一个完全由Weblogic容器保护的Web应用程序。现在,我必须列出当前登录的用户。我必须为此使用Spring Security 2.0.4 在web.xml中,我定义了必要的侦听器和过滤器: 之后,按照我的理解,我定义了bean: 最后,我编写了一个简单的JSP页面,其中列出了用户: 这是我的帮助程序类尝试获取用户列表的方式: 不幸的是,所有这些都不起作用,我也不知道该如何调试。
问题内容: 我正在使用C#HttpWebRequest来获取网页的一些数据。问题是在页面加载后,使用javascript / ajax更新了某些数据,但我没有在响应字符串中获取它。有没有办法让webrequest等待页面中的所有脚本执行完毕? 谢谢 阿米特 问题答案: 如果我正确解释了您的问题,那么您的问题就没有简单的解决方案。 您正在从服务器上抓取HTML,并且由于C#代码不是真正的Web浏览器