金沙澳门官网登录-www.js8.com-金沙澳门官网下载app

金沙澳门官网登录ASP.NET HttpWebRequest和HttpWebRespo

 

F12调出开采人士工具,输入客商名,密码登入,看大家抓到了何等信息。 (此处为360浏览器)

末段实行功效,登入的session已经打响重临。

金沙澳门官网登录ASP.NET HttpWebRequest和HttpWebResponse。 

金沙澳门官网登录 1

金沙澳门官网登录ASP.NET HttpWebRequest和HttpWebResponse。金沙澳门官网登录ASP.NET HttpWebRequest和HttpWebResponse。Form Data:那一个是大家要POST传输的多少:

金沙澳门官网登录ASP.NET HttpWebRequest和HttpWebResponse。任何一些至关重大音信在Request Headers中

userName=xzdylyh&passwd=12313&validateCode=验证码&rememberMe=false  (注意此处恐怕各个人略有差别)

初藳链接:

方式POST

想效仿登入,首先整理一下流水生产线

*****************************************************************

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();//更新验证码
        }
    }
}

金沙澳门官网登录 2

1.透过360浏览器(IE,火狐等等)F12开采人士工具抓到相关数据

Request UOdysseyL:那一个正是登陆哀求的url  

 

HttpWebRequest和HttpWebResponse类是用来发送和吸取HTTP数据的最佳选取。它们协助一多元卓有成效的性能。

3.登录

金沙澳门官网登录 3

我使用C# 设计的winform界面

-------------------------------

2.获得验证码(得到cookie),登入时也需求运用

萧规曹随艺龙旅游网登入

本文由金沙澳门官网登录发布于金沙澳门官网登录,转载请注明出处:金沙澳门官网登录ASP.NET HttpWebRequest和HttpWebRespo

TAG标签:
Ctrl+D 将本页面保存为书签,全面了解最新资讯,方便快捷。