[英]how to set httpclient connect timeout?
I'm struggling with setting connect timeout with c# HttpClient
or its siblings ( HttpClientHandler
, WebRequestHandler
,...) . 我正在努力使用c#
HttpClient
或其兄弟姐妹( HttpClientHandler
, WebRequestHandler
,...)设置连接超时。 There's a timeout property in HttpClient
, but it seems to be a timeout from the beginning of the request until receiving the response. HttpClient
有一个timeout属性,但这似乎是从请求开始到收到响应的超时。 I want to have a method which specify that for example if you don't received ACK from the net socket within 10 seconds for example , then break up and do the next. 我想有一个方法来指定,例如,如果您在10秒钟之内没有从网络套接字接收到ACK,那么请分手并进行下一步。 I saw that there may be something similar in
WinHttpHandler
class, but it seems to be deleted or not available in recent version. 我看到
WinHttpHandler
类中可能有类似的东西,但是它似乎已被删除或在最新版本中不可用。 compare the first link vs second : 比较第一个链接与第二个链接:
1. WinHttpHandler MSDN 1. WinHttpHandler MSDN
2. WinHttpHandler Microsoft Docs 2. WinHttpHandler Microsoft文档
I really need this, because I must differentiate asap between IP's which have a working web servers (maybe slow) vs which don't have a web server at all. 我真的需要这个,因为我必须尽快区分具有正常工作的Web服务器(可能很慢)的IP与根本没有Web服务器的IP。
I use HttpWebRequest.Timeout
in my project to verdict the connection time before establish tcp connection. 我在项目中使用
HttpWebRequest.Timeout
在建立tcp连接之前确定连接时间。 And use HttpWebRequest.ReadOrWriteTimeout
to verdict whole response timeout. 并使用
HttpWebRequest.ReadOrWriteTimeout
判断整个响应超时。 Ps: The HttpClient
seems cut off some useful properties. 附:
HttpClient
似乎切断了一些有用的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.