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 ...
随机推荐
- Java 加载配置文件的方式
一 使用原生方式读取配置文件 1 文件系统加载 Java代码 InputStream in = new FileInputStream("config.properties") ...
- Liunx下NFS服务器的搭建与配置
一.NFS简介 NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源.在NFS的应用中,本地NF ...
- maven_nexus3私服搭建
[maven_nexus3私服搭建] # 00.安装环境说明# (1)Windows7 64位# (2)JDK1.8 64位# (3)Sonatype Nexus Repository OSS 3.1 ...
- C++ 递归实现汉诺塔
C++实现汉诺塔 #include <iostream> using namespace std; void move(int n,char x,char y,char z) { ) { ...
- oracle 字符集 AL32UTF8、UTF8
简介:ORACLE数据库字符集,即Oracle全球化支持(Globalization Support),或即国家语言支持(NLS)其作用是用本国语言和格式来存储.处理和检索数据.利用全球化支持,ORA ...
- jquery方法操作iframe元素
操作iframe父元素 $("#rolesCtl",parent.document).find( 'button' ).trigger( 'click' ); 在父页面获取ifra ...
- java- 控制double输出的小数点位数
像C语言直接 printf("%f.02",float); 非常简单,还可以控制输出的缩距,很是方便. Java就不一样了,但是java也有它的方便之处 下面用列子来解释,用到的 ...
- selenium测试(Java)-- 验证信息(八)
package com.test.validationinfor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.f ...
- Hibernate的getTransaction()和beginTransaction()
session.getTransaction()只是根据session获得一个Transaction实例,但是并没有启动它 session.beginTransaction()在获得一个Transac ...
- c++下面的一个单例
Public FileManager { private FileManager(); public static FileManager Instance=new FileManager(); } ...