System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()
System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()
在请求获取响应结果的时候,超时,具体原因可能就是如下面Jon Skeet所说,
WebResponse implements IDisposable,
so you should use a using statement for it (and for the StreamReader you create from the stream).
If you leave a WebResponse open, it will take up a connection from the connection pool to that host,
and you can end up with timeouts this way.
WebResponse继承IDisposable接口,会释放非托管资源
所以你需要使用声明来创建资源对象
如果你打开WebResponse资源响应,那么他将通过连接池连接主机,使用这个方式,超时将不会成为问题。
应该是这么翻译吧╮(╯_╰)╭
This will close the stream and the response even if an exception is thrown,
so you'll always clean up the resources (in this case releasing the connection back to the pool) promptly.
这个将会关闭stream和response,即使出现抛出异常的情况
所以你总能够即时清理好资源(释放应用池的连接) 这个方式,尝试了一下,暂时没出现什么问题,算解决了99%吧,等到以后再出现什么问题,再来看。
下面是网上找到的一个解决方案:
Author:Jon Skeet
System.Net.WebException: The operation has timed out on HttpWebResponse
This may well be the problem: HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse(); WebResponse implements IDisposable, so you should use a using statement for it (and for the StreamReader you create from the stream). If you leave a WebResponse open, it will take up a connection from the connection pool to that host, and you can end up with timeouts this way. The fixed code would look like this: string responseString;
using (var response = myReq.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream())
{
responseString = reader.ReadToEnd();
}
} This will close the stream and the response even if an exception is thrown, so you'll always clean up the resources (in this case releasing the connection back to the pool) promptly.
System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()的更多相关文章
- System.Net.WebException : The remote server returned an error: (415) UNSUPPORTED MEDIA TYPE
I am having problems with a bit of code that accesses a restful web service. Running this code, it e ...
- C# post数据时 出现如下错误: System.Net.WebException: 操作超时
net(客户端)调用IIS(服务端)出现503后,就报操作超时错误 问题描述: 服务端环境: IIS 客户端环境: windowsxp + iis + .net 调用时出现如下错误: System.N ...
- Method and system for providing security policy for linux-based security operating system
A system for providing security policy for a Linux-based security operating system, which includes a ...
- 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转换为类型“System.Collections.Generic.IList`1
在WPF中DataGrid 选择事件中获取SelectedItems 报错如下 无法将类型为“System.Windows.Controls.SelectedItemCollection”的对象强制转 ...
- 【Winform】 无法将类型为“System.Windows.Forms.SplitContainer”的对象强制转换为类型“System.ComponentModel.ISupportInitialize”。
问题:将dotnet framework 4.0 切换到2.0时,编译没有问题,在运行时出现如下错误:System.InvalidCastException: 无法将类型为“System.Window ...
- 配置IIS提示打开目录浏览时的问题:未能从程序集“System.ServiceModel, Version=3.0.0.0”中加载类型“System.ServiceModel.Activation.HttpModule” 的解决办法
错误消息: 未能从程序集“System.ServiceModel, Version=3.0.0.0”中加载类型“System.ServiceModel.Activation.HttpModule” 的 ...
- “System.FormatException”类型的未经处理的异常在 System.IdentityModel.dll 中发生 其他信息: 十六进制字符串格式无效。
如果你的 WebService 客户端证书配置都没问题,唯独调用接口会出现这个错误 “System.FormatException”类型的未经处理的异常在 System.IdentityModel.d ...
- 关于System.getProperty("java.io.tmpdir");的输出,及System.getProperty();参数
1,首先来介绍下System.getProperty("java.io.tmpdir")输出因为这个输出有点特殊. 理论介绍:他是获取系统临时目录.可以是window的temp,l ...
- WPF System.InvalidCastException: 无法将类型为“System.Windows.Media.Color”的对象强制转换为类型“System.Windows.Media.Brush”。
场景:添加ComboBox样式,界面卡死,日志异常文件如下: -- ::, | ERROR | System.InvalidCastException: 无法将类型为“System.Windows.M ...
随机推荐
- HAProxy+Varnish+LNMP实现高可用负载均衡动静分离集群部署
HAProxy高可用负载均衡集群部署 基本信息: 系统平台:VMware WorkStation 系统版本: CentOS Linux release 7.2.1511 (Core) 内核版本: 3. ...
- Nginx下轻松开启Drupal简洁链接
大家都知道Drupal在apache环境下使用简洁链接是件很轻松的事,因为官方已经把写好的.htaccess文件附在源代码里,一般在配置里直接就可以打开了.但在Nginx下却没有那么简单,但不用担心, ...
- mysql 修改数据库存储地址
默认目录/var/lib/mysql systemctl stop mysqld cp -pr /var/lib/mysql /data/mysql Create a backup of /etc/m ...
- CentOS每次开机都要ifup eth0的解决方法小结
vim /etc/sysconfig/network-scripts/ifcfg-eth0 把里面的 ONBOOT 设为 yes 即可. [编辑]艺搜参考 http://www.jbxue.com/L ...
- 获取页面中更新删除传过来的id
利用uri辅助函数 $id=$this->uri->segment(4); 其中segment(参数) 是表示你要截取获得第几个数据.
- 搭建Grunt集成环境开发SASS
先行下载安装Ruby和SASS 再下载并安装node.js,已经集成了NPM 命令行查看是否安装成功 node -v npm -v 命令行安装grunt npm install -g grunt-cl ...
- 【转】MFC WM_CTLCOLOR 消息
WM_CTLCOLOR消息用来完成对EDIT, STATIC, BUTTON等控件设置背景和字体颜色, 其用法如下: 1.首先在自己需要设置界面的对话框上点击右键-->建立类向导-->加入 ...
- 第三百一十节,Django框架,模板语言
第三百一十节,Django框架,模板语言 模板语言就是可以将动态数据在html模板渲染的语言 一.接收值渲染 locals()函数,写在请求响应render()函数里,可以将逻辑处理函数里的变量传到h ...
- jQuery数组处理详解(转)
1. $.each(array, [callback]) 遍历[常用] 解释: 不同于例遍 jQuery 对象的 $.each() 方法,此方法可用于例遍任何对象(不仅仅是数组哦~). 回调函数拥有两 ...
- perl 字符串比较操作符
perl 中数字和字符串的比较操作符是不一样的 : 其中 == 用于比较数字是否相等:eq 用于比较字符串是否相等: 今天找程序里的bug,结果就是这个操作符用错,哎,赶紧记一下!