- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如果我将客户端连接到的服务指向一个错误的 URL,为什么我得到的 HttpStatusCode 为 0。
我的 statusCodeAsInt 显示为 0。为什么它没有显示为 404 并被处理?
IRestResponse response = client.Execute(restReq);
HttpStatusCode statusCode = response.StatusCode;
var statusCodeAsInt = (int) statusCode;
if (statusCodeAsInt >= 500)
{
throw new InvalidOperationException("A server error occurred: " + response.ErrorMessage, response.ErrorException);
}
if (statusCodeAsInt >= 400)
{
throw new InvalidOperationException("Request could not be understood by the server: " + response.ErrorMessage,
response.ErrorException);
}
处理这个 RestResponse 的正确方法是什么?
最佳答案
在我的案例中,这不是导致 StatusCode 为 0 的防火墙问题。我们使用的旧版应用程序仍在阻止 TLS 1.0 连接的服务器上使用 TLS 1.0。一旦我们启用了 TLS 1.2,我们就得到了我们期望的状态代码。
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
关于c# - 获取 0 的 HttpStatusCode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34795818/
HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); HttpStatusCode statusC
我正在尝试引发 HttpResponseException,如该截屏视频中所述(大约 1 分钟) throw new HttpResponseException(HttpStatusCode.Unau
假设我有以下变量: System.Net.HttpStatusCode status = System.Net.HttpStatusCode.OK; 如何检查这是成功状态码还是失败状态码? 例如,我可
我正在编写 XUnit 测试用例。我收到以下错误 Error CS1061 'HttpStatusCode' does not contain a definition for 'Should' an
我正在编写 XUnit 测试用例。我收到以下错误 Error CS1061 'HttpStatusCode' does not contain a definition for 'Should' an
我希望返回 202 - HttpStatusCode.Accepted - 以及一个字符串值。 这怎么写: [HttpPost] public async Task Post() { retu
无论如何我们可以在异常捕获时获取 HttpStatus 代码吗?异常可能是 Bad Request、408 Request Timeout、419 Authentication Timeout?如何在
我正在对一个简单的 Controller 进行单元测试,检查在传入空 ID 时它是否返回 400 代码。但是,当我对此进行测试时,返回的结果并不等于 400 错误代码。 我的代码: int? null
在我的使用 ssl 与服务器通信的 Windows Phone 应用程序中出现了一些问题。对于从服务器 HttpStatusCode.NotFound 收到的每个请求客户端。我该如何解决这个问题? 在
根据 IANA registry还有更多标准状态代码,例如 507 (InsufficientStorage)。我正在编写一个 webdav 服务器库,并且在我的类中使用 HttpStatusCode
我们已经使用 WCF 编写了一个 Restful 服务,现在正在尝试编写 FitNesse 测试来验证该服务的行为。 一个测试是如果找不到资源则返回 404 状态码。 问题是我们找不到一种机制来使用允
如果我将客户端连接到的服务指向一个错误的 URL,为什么我得到的 HttpStatusCode 为 0。 我的 statusCodeAsInt 显示为 0。为什么它没有显示为 404 并被处理? IR
我想知道是否有更简单的方法(更好的方法)来检查 500 状态代码? 我能想到的唯一方法是: var statusCodes = new List() { HttpStatusCode.BadGat
我正在使用 .NET MVC。 当我回来时new HttpResult(HttpStatusCode.NoContent);创建的对象具有状态代码 = 200: {ServiceStack.Commo
我正在尝试使用 ServiceStack.Razor 运行一个最小的应用程序,但我在运行 CustomHttpHandler 时遇到了问题。我已按照说明进行操作 here和 here ,但它无法正常工
这个问题在这里已经有了答案: Getting Http Status code number (200, 301, 404, etc.) from HttpWebRequest and HttpWe
我正在使用 ASP.NET MVC 4,我需要返回状态代码 420,这在 HttpStatusCode 枚举值中找不到。 通常这很简单,你可以这样做: return Request.CreateRes
我正在编码 C# WebApi 2 webservice,我有一个关于返回 HttpStatusCode 的问题来自 IQueryable网络服务功能。 如果网络服务函数返回单个对象,则可以轻松使用以
我正在设置 ProducesResponseType,以便用 Swagger 记录它。 如果响应成功(OK => 200),那么它会生成一个 IEnumerable。 [ProducesRespons
根据以下网站,您可以将异常参数传递给 HttpResponseMessage.CreateErrorResponse 方法 ( https://msdn.microsoft.com/en-us/lib
我是一名优秀的程序员,十分优秀!