本文介绍了如何设置httpwebrequest超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经按照以下方式设置了HttpWebRequest的时间。
I've set HttpWebRequest time out like following way.
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ImageUrl); request.Method = "HEAD"; request.UseDefaultCredentials = true; request.Accept = "*/*"; request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials; bool exist = false; try{ //request.ReadWriteTimeout = 1000; request.Timeout = 1000; request.GetResponse(); exist = true; } catch{ // } <pre> Whenever a request is made on ImageUrl which is not exist, it takes too much time to get request response. It's taking too much time for ImageUrls which starts with Https:// What I have tried: I've tried above code but not getting request timeout. Is the code right or wrong? when a request made for ImageUrl on which image is not exist, it takes morethan 2seconds to get response of the request.推荐答案
你有在web.config文件中设置Request Timeout 例如 You have to set Request Timeout in your web.config file for example <system.web> <httpRuntime executionTimeout="160" /> </system.web>
欲了解更多信息,请关注belo w链接 增加请求超时? [ ^ ] 长ASP.NET操作的IIS请求超时 - 堆栈溢出 [ ^ ] 如何增加请求/响应的超时时间? | ASP.NET论坛 [ ^ ] 问候, AARIF SHAIKH
for more information please follow below links increase request timeout ? [^] IIS Request Timeout on long ASP.NET operation - Stack Overflow[^] How to increase the time out for request/response ? | The ASP.NET Forums[^] Regards, AARIF SHAIKH
您可以设置请求对象的Timeout属性。 you can set the Timeout property of your request object. request.Timeout = 3000
注意:该值以毫秒为单位。
更多推荐
如何设置httpwebrequest超时?
发布评论