zoukankan      html  css  js  c++  java
  • GetResponse() 基础连接已经关闭:服务器关闭了本应保持活动状态的连接

    1.原因:

    (1)KeepAlive默认为true,与internet保持持续连接 ,服务器关闭了连接,使用HttpWebResponse.GetResponse()出错

    (2)HttpWebRequest 超过了最大连接数

    (3)网络响应慢而导致超时

    2.解决:

    (1) req.KeepAlive = false;

    (2)设置超时时间 req.Timeout = 15000;

    (3)连续使用HttpWebRequest请求时,要使用sleep(100),放大http请求时间间隔

    (4) 突破该程序的http的最大连接数

    ServicePoint 对象允许的最大并发连接数。默认值为 2。

    1,在代码中修改:
    system.net.ServicePointManager.DefaultConnectionLimit=100//把最大连接数改为100
    2,在配置文件(app.config)中修改:
    <configuration>
      <system.net>
        <connectionManagement>
          <!--表示把对任何域名的请求最大http连接数都设置为100-->
          <add address = "*" maxconnection = "100" />
        </connectionManagement>
      </system.net>
    </configuration>

    (5)保证每次用完都要关闭

    if (res != null)
    {
          res.Close();
          res = null;
    }
    
     if (req != null)
    {
         req.Abort();
         req = null;
    }
    

      

  • 相关阅读:
    给存储过程传递一个表
    Linker problems with Borland builder
    Python内置函数super的不便之处
    接口测试基础
    接口测试工具篇postman
    接口测试工具篇jmeter
    git的使用
    git与pycharm结合使用
    抓包工具fiddler
    sql 中 case when 语法
  • 原文地址:https://www.cnblogs.com/yaosj/p/6705203.html
Copyright © 2011-2022 走看看