• 周一. 6月 24th, 2024

5G编程聚合网

5G时代下一个聚合的编程学习网

热门标签

转载,(无法从传输中读取数据 )

admin

11月 28, 2021

c#文章好找啊,记录一下,参考解决地址:https://www.cnblogs.com/LL-723/p/4268020.html

直接贴代码

string responseContent = “”;

            int count = 0;

            Stream responseStream;

            string restring;

            try

            {

                System.GC.Collect();

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                request.Method = “PROPFIND”;

                request.KeepAlive=false;

                ServicePointManager.DefaultConnectionLimit = 500;

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();

              

                lock (sign)

                {

                    //using (Stream resStream = response.GetResponseStream())

                    //{

                    //    using (StreamReader reader = new StreamReader(resStream, Encoding.UTF8))

                    //    {

                    //        responseContent = reader.ReadToEnd();

                    //    }

                    //}

                    //restring = responseContent;

                    //方式1

                    responseStream = response.GetResponseStream();

                  

                    MemoryStream ms = new MemoryStream();

                    responseStream.CopyTo(ms);

                    byte[] bt = ms.ToArray();

                    restring = System.Text.Encoding.UTF8.GetString(bt);

                    ms.Close();

                    responseStream.Close();

                    request.Abort();

                    request = null;

                    response.Close();

                    response=null;

                  

                }

            }

            catch (Exception ex)

            {}

其中内存流方式

                   responseStream = response.GetResponseStream();

                  

                    MemoryStream ms = new MemoryStream();

                    responseStream.CopyTo(ms);

                    byte[] bt = ms.ToArray();

                    restring = System.Text.Encoding.UTF8.GetString(bt);

能解决无法从传输连接中读取数据: 远程主机强迫关闭了一个现有的连接的问题

————————————————

版权声明:本文为CSDN博主「菜鸟王小凡」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/wqs15192095633/article/details/109122811

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注