代码之家  ›  专栏  ›  技术社区  ›  Fabio Milheiro

在接收到与OK不同的HTTP状态后,如何获取XML响应?

  •  0
  • Fabio Milheiro  · 技术社区  · 15 年前

    httpRequest.getResponse()方法获取状态代码422(不可处理的实体),并引发异常。在我使用的这个WebService中,我知道也发送了一个XML响应,我需要得到那个响应,以便找出服务器为什么不能处理我的请求。

    如何在catch块中获取XML响应?

    try
    {
        // Submits the HTTP request to create the invoice and gets the XML response.
        using (HttpWebResponse httpResponse = httpRequest.GetResponse() as HttpWebResponse)
        {
            // my code...
            return httpResponse;
        }
    }
    catch (Exception e)
    {
    }
    
    1 回复  |  直到 15 年前
        1
  •  2
  •   maciejkow    15 年前

    捕获WebException并访问E.Response属性。