博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse()
阅读量:4538 次
发布时间:2019-06-08

本文共 1747 字,大约阅读时间需要 5 分钟。

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:

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.

 

转载于:https://www.cnblogs.com/danlis/p/5366967.html

你可能感兴趣的文章
util.promisify 的那些事儿
查看>>
配置phpstudy+phpstorm+xdebug环境
查看>>
BZOJ 1079 [SCOI2008]着色方案
查看>>
[Win8.1系统]双系统
查看>>
HDU 3899 树形DP
查看>>
获取当前页面url信息
查看>>
Java容器类源码分析前言之集合框架结构(基于JDK8)
查看>>
linux下C/C++程序的内存布局
查看>>
单词计数问题
查看>>
php 魔术方法 __autoload()
查看>>
js div拖动动画运行轨迹效果
查看>>
Recipe 1.9. Processing a String One Word at a Time
查看>>
Linux 下查看系统是32位 还是64 位的方法
查看>>
MySQL 引擎 和 InnoDB并发控制 简介
查看>>
Dave Python 练习二
查看>>
第二章 第五节 获取帮助
查看>>
关于源代码及其管理工具的总结
查看>>
此文对你人生会有莫大好处的,建议永久保存 2013-07-26 11:04 476人阅读 评论(0) ...
查看>>
JQuery怎样返回前一页
查看>>
Best Time to Buy and Sell Stock
查看>>