HttpWebRequest .Net Core 设置超时

HttpWebRequest .Net Core set Timeout

我正在尝试在 HttpWebRequest 上设置超时,但在 .Net Core 中似乎不可能。 属性 'Timeout' 已经不存在了。

谢谢

I am trying to set the Timeout on an HttpWebRequest and it seems that it is not possible in .Net Core.

如果您使用的是 .NET Core 2.0,则可以在 .NET Core 中使用。可以看到the support for the Timeout property here

如果可以,请使用 System.Net.Http.HttpClient instead, because...

In general, for better app performance and features, we recommend developers move away from HttpWebRequest and adopt HttpClient API surface.