title: Encoding with HttpClient in .NET 4.5
body: <p>I'm consuming some data using the <a href="/questions/tagged/fogbugz" class="post-tag" title="show questions tagged &#39;fogbugz&#39;" rel="tag">fogbugz</a> XML API. This API always offers data as UTF-8.</p>
  
  <p>When using the <code>WebClient</code> class for making a request I am able to set the encoding. For example:</p>
  
  <pre><code>var result = new WebClient(); 
  result.Encoding = Encoding.UTF8;
  </code></pre>
  
  <p>But what about the <code>HttpClient</code> class?</p>
  
  <pre><code>HttpClient client = new HttpClient();
  </code></pre>
  
  <p>Should I use:</p>
  
  <pre><code>client.GetByteArrayAsync(url);
  </code></pre>
  
  <p>...and then convert the bytes from the encoding (UTF-8) to a string?</p>
  
  <p>Or is there a way to directly get the content as a UTF-8 string?</p>
  
  <pre><code>using (var client = Connector.GetHttpClient())
  {
      var byteData = await client.GetByteArrayAsync(url);
      data = Encoding.UTF8.GetString(byteData);
  }
  </code></pre>
  
  <p>Finally, here is an excerpt from the XML response:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;response&gt;
  </code></pre>