我们如何捕获.net Framework 4.7.2中的错误429(请求过多)?

问题描述 投票:0回答:1
.net framwork 4.7.2 中的 HttpStatusCode 确实有 429 错误代码。 我们还能用什么来代替这个来捕获 429 错误,因为我只想在出现 429 错误问题时才执行某些操作。

catch (WebException ex) { if (ex.Response is HttpWebResponse response && response.StatusCode == HttpStatusCode.) { } }
这是我正在使用的当前 catch 块,但 HttpStatusCode 不包含 429 的任何属性。

c# asp.net http-status-code-429 webexception
1个回答
0
投票
虽然 HTTP 状态代码 429 没有预定义的枚举值,但您仍然可以将整数 429 转换为

HttpStatusCode

:

response.StatusCode == ((HttpStatusCode)429)
    
© www.soinside.com 2019 - 2024. All rights reserved.