日期:2014-05-17  浏览次数:20846 次

请求HttpWebRequest中读取数据超慢等问题
     byte[] postData = Encoding.ASCII.GetBytes(parameters);
            System.Net.HttpWebRequest request = System.Net.WebRequest.Create(url) as System.Net.HttpWebRequest;
            request.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
            request.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
            request.Headers.Add("Accept-Encoding", "gzip, deflate");
            request.CookieContainer = cookieContainer;
            request.ContentLength = postData.Length;
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)";

 System.IO.Stream outputStream = request.GetRequestStream();
            outputStream.Write(postData, 0, postData.Length);
            outputStream.Close();
            System.Net.HttpWebResponse response = request.GetResponse() as System.Net.HttpWebResponse;

 System.IO.Stream readStream = response.GetResponseStream();
            string responseText = "";
            try
            {
                if (response.ContentEncoding.ToLower().Contains("gzip"))
                    readStream = new GZipStream(readStream, CompressionMode.Decompress);
                else if (response.ContentEncoding.ToLower().Contains("deflate"))
                    readStream = new DeflateStream(readStream, CompressionMode.Decompress);

                System.IO.StreamReader reader = new System.IO.StreamReader(readStream, Encoding);
                responseText = reader.ReadToEnd();
            }
            finally
            {<