【问题标题】:Extract HttpError from HttpResponseException从 HttpResponseException 中提取 HttpError
【发布时间】:2015-11-06 10:07:23
【问题描述】:

如果出现错误,我会从我调用的 REST 服务中获得 HTTPResponseException。我想从中获取错误消息的详细信息,以便我可以相应地处理。如何提取返回的 HTTPResponseException 的错误数据或内部异常信息?

【问题讨论】:

    标签: c# .net exception asp.net-web-api


    【解决方案1】:

    HttpResponseException 继承自 Exception 的属性,因此一旦您拥有 HTTPResponseException 对象,您就可以简单地读取内部异常,如下所示。

    catch(HttpResponseException e) {
         if (e.InnerException != null)
            Console.WriteLine("Inner exception: {0}", e.InnerException);
      }
    

    【讨论】:

    • 谢谢。关于如何提取 HttpError 的任何想法
    • HttpReponseException 有一个属性 Response ,您可以阅读它 Console.WriteLine("Inner exception: {0}", e.Response);我发布的 URL 将显示异常提供的所有信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2012-09-26
    相关资源
    最近更新 更多