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 ...
随机推荐
- JS地毯式学习三
1. 插件是一类特殊的程序 . 他可以扩展浏览器的功能 , 通过下载安装完成 . 比如 , 在线音乐.视频动画等等插件. // 检测非 IE 浏览器插件是否存在function hasPlugin(n ...
- tomcat7项目启动报错java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory
报这个错说明用的是tomcat7 打开myeclipse,Preferentces->MyEclipse->Servers->Tomcat->Tomcat 6.x ,载入 ...
- print spooler 服务无法启动 打印机全部消失
这往往是失败的打印任务导致的. 打开 C:\Windows\System32\spool\PRINTERS ,这个目录下的文件全是打印缓存,失败的任务也保存在这里.把这里的文件全部删除,然后再重新启动 ...
- Rattle:数据挖掘的界面化操作
R语言是一个自由.免费.源代码开放的软件,它是一个用于统计计算和统计制图的优秀工具.这里的统计计算可以是数据分析.建模或是数据挖掘等,通过无数大牛提供的软件包,可以帮我们轻松实现算法的实施. 一些读者 ...
- [Eclipse] 项目编码
一.修改eclipse的新建项目的编码 在菜单栏的 Window->Preferences->General->Workspace->Text file encoding 将其 ...
- Semi-Supervised Classification with Graph Convolutional Networks
Kipf, Thomas N., and Max Welling. "Semi-supervised classification with graph convolutional netw ...
- Linux之查看文件大小和数目
1.查看当前文件大小du -sh ./ du [-abcDhHklmsSx] [-L <符号连接>][-X <文件>][--block-size][--exclude=< ...
- Java运行时,各种类型存储介绍
Java的内存分配 Java程序运行时的内存结构分成:方法区.栈内存.堆内存.本地方法栈几种. 方法区 存放装载的类数据信息,包括:基本信息:每个类的全限定名.每个类的直接超类的全限定 ...
- 【问题】报错[CRITICAL] Rendering SLS 'base:minions.install' failed: Jinja variable 'list' object has no element 0
1.报错[CRITICAL] Rendering SLS 'base:minions.install' failed: Jinja variable 'list' object has no elem ...
- perl readlink 函数-返回软链接指向的文件
readlink 函数专门用于处理链接,可以返回该链接指向的文件的路径 代码示例: print readlink($prog) if (-f $prog && -l $prog):