title: Decompressing GZip Stream from HTTPClient Response
body: <p>I am trying to connect to an api, that returns GZip encoded JSON, from a WCF service (WCF service to WCF service). I am using the <strong>HTTPClient</strong> to connect to the API and have been able to return the JSON object as a string. However I need to be able to store this returned data in a database and as such I figured the best way would be to return and store the JSON object in an array or byte or something along those lines. </p>
  
  <p>What I am having trouble with specifically is the decompressing of the GZip encoding and have been trying lots of different example but still cant get it. </p>
  
  <p>The below code is how I am establishing my connection and getting a response, this is the code that returns a string from the API.</p>
  
  <pre><code>public string getData(string foo)
  {
      string url = "";
      HttpClient client = new HttpClient();
      HttpResponseMessage response;
      string responseJsonContent;
      try
      {
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
          response = client.GetAsync(url + foo).Result;
          responseJsonContent = response.Content.ReadAsStringAsync().Result;
          return responseJsonContent;
      }
      catch (Exception ex)
      {
          System.Windows.Forms.MessageBox.Show(ex.Message);
          return "";
      }
  }
  </code></pre>
  
  <p>I have been following a few different examples like these <a href="https://web.archive.org/web/20150312130407/http://cgeers.com/2011/10/02/stack-exchange-api/" rel="noreferrer">StackExchange API</a>, <a href="https://msdn.microsoft.com/en-us/library/system.io.compression.gzipstream%28v=vs.110%29.aspx" rel="noreferrer">MSDN</a>, and a couple on stackoverflow, but I haven't been able to get any of these to work for me. </p>
  
  <p>What is the best way to accomplish this, am I even on the right track? </p>
  
  <p>Thanks guys.</p>