模拟艺龙旅游网登录,供大家参考,具体内容如下
想模拟登录,首先整理一下流程
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-/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已经成功返回。