zoukankan      html  css  js  c++  java
  • 转载,(无法从传输中读取数据 )

    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

  • 相关阅读:
    python小技巧之把list组合成chain
    airflow自动生成dag
    python之json读写
    Java写入的常用技巧(二)
    python并发——信号量
    python并发——进程间同步和通信
    python并发——从线程池获取返回值
    python获取hive表时间格式最大分区
    python递归获取目录下指定文件
    国际化(i18n)
  • 原文地址:https://www.cnblogs.com/bingyizhihun/p/15166841.html
Copyright © 2011-2022 走看看