title: C# - WebClient.DownloadString does not detect response encoding
body: <p>As I was working with <code>WebClient</code> class, I noticed that a simple call like this</p>
  
  <pre><code>string downloadedString = new WebClient().DownloadString("http://whatever");
  </code></pre>
  
  <p>produced a string using an incorrect encoding, even though the response contained a proper <code>Content-Type</code> header <code>application/json; charset=utf-8</code>. </p>
  
  <p>When I looked at the <a href="http://referencesource.microsoft.com/#System/net/System/Net/webclient.cs,3688e959a4f704f8" rel="nofollow">source code</a> I found out that <code>DownloadString</code> doesn't look at the response headers at all. Instead it uses <code>request.ContentType</code> and if the charset is not present there, it uses the <code>Encoding</code> property (which has to be set beforehand, otherwise it will be system's default). </p>
  
  <p>It seems weird that we have to specifically tell the <code>WebClient</code> object which encoding to use before sending the request (by adding a <code>Content-Type</code> header or setting encoding directly). It becomes pointless to use <code>DownloadString</code>: if we want the right encoding, we have to use <code>DownloadData</code> or plain old <code>WebRequest</code> and write code that parses response headers manually in order to get the correct response string.</p>
  
  <p>Does anyone know the reason for such behavior?
  Is there a better way in .NET to properly download HTTP string response, than manually parsing response <code>Content-Type</code>?</p>