欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
c# 實(shí)現網(wǎng)頁(yè)上用戶(hù)自動(dòng)登陸|asp.net 模擬網(wǎng)站登錄---學(xué)習頻道--商務(wù)湖南---...

c# 實(shí)現網(wǎng)頁(yè)上用戶(hù)自動(dòng)登陸|asp.net 模擬網(wǎng)站登錄---學(xué)習頻道--商務(wù)湖南----c#,asp.net,css,javascript,html,sql,jquery學(xué)習

默認分類(lèi) 2010-05-10 15:44:52 閱讀126 評論0   字號: 訂閱

c# 實(shí)現網(wǎng)頁(yè)上用戶(hù)自動(dòng)登陸|asp.net 模擬網(wǎng)站登錄

2010-01-08 06:52:12  

using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.IO;

namespace Czt.Web
{
    /// <summary>
    /// 實(shí)現網(wǎng)站登錄類(lèi)
    /// </summary>
    public class Post
    {
        /// <summary>
        /// 網(wǎng)站Cookies
        /// </summary>
        private string _cookieHeader = string.Empty;
        public string CookieHeader
        {
            get
            {
                return _cookieHeader;
            }
            set
            {
                _cookieHeader = value;
            }
        }
        /// <summary>
        /// 網(wǎng)站編碼
        /// </summary>
        private string _code = string.Empty;
        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }


        private string _pageContent = string.Empty;
        public string PageContent
        {
            get { return _pageContent; }
            set { _pageContent = value; }
        }

        private Dictionary<string, string> _para = new Dictionary<string, string>();
        public Dictionary<string, string> Para
        {
            get { return _para; }
            set { _para = value; }
        }


        /**/
        /// <summary>
        /// 功能描述:模擬登錄頁(yè)面,提交登錄數據進(jìn)行登錄,并記錄Header中的cookie
        /// </summary>
        /// <param >登錄數據提交的頁(yè)面地址</param>
        /// <param >用戶(hù)登錄數據</param>
        /// <param >引用地址</param>
        /// <param >網(wǎng)站編碼</param>
        /// <returns>可以返回頁(yè)面內容或不返回</returns>
        public string PostData(string strURL, string strArgs, string strReferer, string code, string method)
        {
            return  PostData(strURL,  strArgs,  strReferer,  code,  method, string.Empty);
        }
        public string PostData(string strURL, string strArgs, string strReferer, string code, string method, string contentType)
        {
            try
            {
                string strResult = "";
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
                myHttpWebRequest.AllowAutoRedirect = true;
                myHttpWebRequest.KeepAlive = true;
                myHttpWebRequest.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*";
                myHttpWebRequest.Referer = strReferer;


                myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";

                if (string.IsNullOrEmpty(contentType))
                {
                    myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
                }
                else
                {
                    myHttpWebRequest.ContentType = "contentType";
                }

                myHttpWebRequest.Method = method;

                myHttpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");

                if (myHttpWebRequest.CookieContainer == null)
                {
                    myHttpWebRequest.CookieContainer = new CookieContainer();
                }

                if (this.CookieHeader.Length > 0)
                {
                    myHttpWebRequest.Headers.Add("cookie:" + this.CookieHeader);
                    myHttpWebRequest.CookieContainer.SetCookies(new Uri(strURL), this.CookieHeader);
                }

                byte[] postData = Encoding.GetEncoding(code).GetBytes(strArgs);
                myHttpWebRequest.ContentLength = postData.Length;

                System.IO.Stream PostStream = myHttpWebRequest.GetRequestStream();
                PostStream.Write(postData, 0, postData.Length);
                PostStream.Close();

                HttpWebResponse response = null;
                System.IO.StreamReader sr = null;
                response = (HttpWebResponse)myHttpWebRequest.GetResponse();

                if (myHttpWebRequest.CookieContainer != null)
                {
                    this.CookieHeader = myHttpWebRequest.CookieContainer.GetCookieHeader(new Uri(strURL));
                }

                sr = new System.IO.StreamReader(response.GetResponseStream(), Encoding.GetEncoding(code));    //    //utf-8
                strResult = sr.ReadToEnd();
                sr.Close();
                response.Close();
                return strResult;
            }
            catch (Exception ex)
            {
                Utilities.Document.Create("C:\\error.log", strArgs, true, Encoding.UTF8);
            }
            return string.Empty;
        }

        /**/
        /// <summary>
        /// 功能描述:在PostLogin成功登錄后記錄下Headers中的cookie,然后獲取此網(wǎng)站上其他頁(yè)面的內容
        /// </summary>
        /// <param >獲取網(wǎng)站的某頁(yè)面的地址</param>
        /// <param >引用的地址</param>
        /// <returns>返回頁(yè)面內容</returns>
        public string GetPage(string strURL, string strReferer, string code)
        {
            return GetPage(strURL, strReferer,code,string.Empty);
        }
        public string GetPage(string strURL, string strReferer,string code,string contentType)
        {
            string strResult = "";
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(strURL);
            myHttpWebRequest.AllowAutoRedirect = true;
            myHttpWebRequest.KeepAlive = false;
            myHttpWebRequest.Accept = "*/*";
            myHttpWebRequest.Referer = strReferer;
            myHttpWebRequest.Headers.Add("Accept-Encoding", "gzip, deflate");

            myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 2.0.50727)";
            if (string.IsNullOrEmpty(contentType))
            {
                myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
            }
            else
            {
                myHttpWebRequest.ContentType = contentType;
            }
            myHttpWebRequest.Method = "GET";

            if (myHttpWebRequest.CookieContainer == null)
            {
                myHttpWebRequest.CookieContainer = new CookieContainer();
            }

            if (this.CookieHeader.Length > 0)
            {
                myHttpWebRequest.Headers.Add("cookie:" + this.CookieHeader);
                myHttpWebRequest.CookieContainer.SetCookies(new Uri(strURL), this.CookieHeader);
            }


            HttpWebResponse response = null;
            System.IO.StreamReader sr = null;
            response = (HttpWebResponse)myHttpWebRequest.GetResponse();


            Stream streamReceive;
            string gzip = response.ContentEncoding;

            if (string.IsNullOrEmpty(gzip) || gzip.ToLower() != "gzip")
            {
                streamReceive = response.GetResponseStream();
            }
            else
            {
                streamReceive = new System.IO.Compression.GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
            }

            sr = new System.IO.StreamReader(streamReceive, Encoding.GetEncoding(code));

            if (response.ContentLength > 1)
            {
                strResult = sr.ReadToEnd();
            }
            else
            {
                char[] buffer=new char[256];
                int count = 0;
                StringBuilder sb = new StringBuilder();
                while ((count = sr.Read(buffer, 0, buffer.Length)) > 0)
                {
                    sb.Append(new string(buffer));
                }
                strResult = sb.ToString();
            }
            sr.Close();
            response.Close();
            return strResult;
        }

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
C#寫(xiě)一個(gè)采集器
如果向某網(wǎng)址Post信息,并得到CookieContainer以便以后直接通過(guò)驗證 - g...
【JAVA】mht文件轉html
微信公眾平臺向特定用戶(hù)推送消息
C#帶cookie Post和Get方式發(fā)送數據,保持cookie
C# HttpWebRequest 通用類(lèi)2 - 轉 - afish1984 - 博客園
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久