国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

HttpRequest重寫,解決資源戰(zhàn)勝/鏈接超時/分塊下載事件通知 問題。

2019-11-17 02:18:49
字體:
供稿:網(wǎng)友

HttPRequest重寫,解決資源戰(zhàn)勝/鏈接超時/分塊下載事件通知 問題。

/************************************************************************************** 文 件 名:WebRequest.cs* 創(chuàng)建時間:2015-06-18* 作 者:Sam Shum (s.sams@m(xù)sn.com)* 說 明:解決WebHttpRequest下載網(wǎng)頁數(shù)據(jù)出現(xiàn)問題 * 修改時間:2015-06-19* 修 改 人:Sam Shum*************************************************************************************/using System;using System.Collections.Generic;using System.ComponentModel;using System.IO;using System.IO.Compression;using System.Linq;using System.Net;using System.Text;using System.Web;namespace S.Sams.Common{    public class HttpRequest    {        public HttpRequest()        {            //string Url = "http://localhost:5192/api/Cab/5";            //string httpMethod = "PUT";            //string httpContent = "{'Name': 'B90', 'Color': 'Green', 'Height': 1590, 'Width': 4500 }";            //Encoding httpCode = Encoding.Default;            //Console.WriteLine(Get(Url, httpMethod, httpContent, httpCode));            setEncoding = Encoding.Default;        }        public HttpRequest(string url, string method) : base()        {            setUrl = url;            setMethod = method;        }        /// <summary>        /// 服務請求地址 http://www.aaa.com/        /// </summary>        public string setUrl { get; set; }        /// <summary>        /// 服務請求方法:GET/POST/PUT/DELETE        /// </summary>        public string setMethod { get; set; }        /// <summary>        /// 設置服務請求數(shù)據(jù)類型        /// </summary>        [DefaultValue("text/html")]        public string setContentType { get; set; }        /// <summary>        /// 設置服務頁面編碼        /// </summary>        public Encoding setEncoding { get; set; }        public delegate void DownloadStartDelegate(int httpStatusCode);        public delegate void DownloadProcessDelegate(long totalLength, long DownloadedByte, float percent);        public delegate void DownloadEndDelegate(long totalLength);        public event DownloadStartDelegate DownloadStart;        public event DownloadProcessDelegate DownloadProcess;        public event DownloadEndDelegate DownloadEnd;        public string Get()        {            return Get(setUrl);        }        public string Get(string setUrl)        {            return Get(setUrl, "GET", null, setEncoding);        }        public string Get(string setUrl, string httpContent)        {            return Get(setUrl, "POSE", httpContent, setEncoding);        }        public string Get(string Url, string httpMethod, string httpContent, Encoding httpCode)        {            if (string.IsNullOrWhiteSpace(Url) || string.IsNullOrWhiteSpace(httpMethod))            {                throw new ArgumentException("Url or HttpMethod 參數(shù)不能為空!");            }            GC.Collect();            StringBuilder content = new StringBuilder();            HttpWebRequest request = null;            HttpWebResponse response = null;            StreamWriter sw = null;            try            {                ServicePointManager.DefaultConnectionLimit = 512;                request = WebRequest.Create(Url) as HttpWebRequest;                request.Method = httpMethod;                request.AllowAutoRedirect = true;                request.KeepAlive = false;                request.Accept = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; Maxthon 2.0)";                request.ContentType = setContentType; //"application/octet-stream";                request.Proxy = null;                if (httpContent != null && !string.IsNullOrWhiteSpace(httpContent))                {                    using (sw = new StreamWriter(request.GetRequestStream()))                    {                        sw.Write(httpContent);                    }                }                using (response = request.GetResponse() as HttpWebResponse)                {                    if (this.DownloadStart != null)                        this.DownloadStart((int)response.StatusCode);                    Stream stream = response.GetResponseStream();                    if (response.ContentEncoding.ToLower().Contains("gz


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 贵州省| 屏山县| 灌阳县| 九龙坡区| 江山市| 托里县| 宁武县| 沙河市| 南靖县| 乌审旗| 枝江市| 开鲁县| 车致| 石柱| 综艺| 文山县| 安多县| 夹江县| 防城港市| 原阳县| 黄浦区| 精河县| 德清县| 库尔勒市| 沙洋县| 麦盖提县| 凌源市| 长丰县| 鄂温| 四平市| 旬阳县| 乌鲁木齐市| 盘锦市| 射洪县| 宁乡县| 汕头市| 清新县| 读书| 乌兰察布市| 长海县| 夹江县|