如何设置httpwebrequest超时?

编程入门 行业动态 更新时间:2024-10-26 14:31:50
本文介绍了如何设置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超时?

本文发布于:2023-11-05 19:40:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561667.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何设置   httpwebrequest

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!