title: How to get the JSON error message from HttpRequestException
body: <p>I have a situation where in I have to extract a Response(<code>HttpResponseMessage</code>) in a <code>catch</code> statement but that I suppose can't be done (using <code>await</code> in catch).
  Also if i do it after catch , the <code>HttpResponseMessage</code> message gets "Disposed".
  Code: </p>
  
  <pre><code> private async void MakeHttpClientPostRequest()
   {
       HttpResponseMessage response = null;
       try
       {
           HttpClient httpClient = new HttpClient();
           httpClient.Timeout = TimeSpan.FromSeconds(15);
           HttpContent httpContent = null;
           if (postJSON != null)
           {
               httpContent = new StringContent(postJSON);
               httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
           }
  
           response = await httpClient.PostAsync(url, httpContent);
           if (response != null)
           {
               response.EnsureSuccessStatusCode();
               netResults = await response.Content.ReadAsStringAsync();
           }
  
           if (this.convertedType != null)
           {
               MemoryStream assetReader = GetMemoryStreamFromString(netResults);
               assetReader.Position = 0;
               object value = fromJSON(assetReader, this.convertedType);
               networkReqSuccessWithObjectCallback(this, value);
           }
           else
           {
               //Return netResult as string.
               networkReqSuccessWithStringCallback(this, netResults);
           }
       }
  
       catch (TaskCanceledException)
       {
           ErrorException ee = null;
           ee = new ErrorException("RequestTimeOut");
           NotifyNetworkDelegates(ee);
       }
       catch (HttpRequestException ex)
       {
           //HERE I have to extract the JSON string send by the server
       }
       catch (Exception)
       {
       }
  }
  </code></pre>
  
  <p>What can be done here ?</p>
  
  <hr>
  
  <p><strong>Update</strong>
  Previous approach using <code>HttpWebRequest</code> :</p>
  
  <pre><code>public void MakePostWebRequest()
  {
      //WebCalls using HttpWebrequest.
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
      request.CookieContainer = new CookieContainer();
      request.ContentType = "application/json";
      request.Method = "POST";
      requestState = RequestState.ERequestStarted;
      asyncResult = request.BeginGetRequestStream(new AsyncCallback(GetRequestStream), request);
  }
  
  
  private void GetRequestStream(IAsyncResult asyncResult)
  {
      HttpWebRequest request = (HttpWebRequest)asyncResult.AsyncState;
      {
          try
          {
              Stream requestStream = request.EndGetRequestStream(asyncResult);
              if (request != null)
              {
                  using (requestStream)
                  {
                      StreamWriter writer = new StreamWriter(requestStream);
                      writer.Write(postJSON);
                      writer.Flush();
                  }
              }
          }
          catch (WebException we)
          {
          }
      }
  }
  
  private void GetResponseStream(IAsyncResult asyncResult)
  {
      requestState = RequestState.EResponseStream;
  
      HttpWebRequest request = asyncResult.AsyncState as HttpWebRequest;
      HttpWebResponse response;
      try
      {
          response = (HttpWebResponse)request.EndGetResponse(asyncResult);
          using (StreamReader reader = new StreamReader(response.GetResponseStream()))
          {
              netResults = reader.ReadToEnd();
          }
          requestState = RequestState.ERequestCompleted;
      }
      catch (WebException we)
      {
          // failure
          ErrorException ee = null;
          response = we.Response as HttpWebResponse;
          if (response != null)
          {
              using (StreamReader reader = new StreamReader(response.GetResponseStream()))
              {
                  //HERE I'm getting the json error message
                  netResults = reader.ReadToEnd();
              }
          }
      }
      catch (Exception e)
      {
          networkReqFailedCallback(this, e);
      }
  }
  </code></pre>