title: Character encoding problem with HttpClient.PostAsync
body: <p>We have a legacy web app which runs ok manually from within browsers. When I try to use the same web app from within code using http posts, I get some Turkish characters as ?.</p>
  <p>I have the following code to make a http post:</p>
  <pre><code>var httpClient = new HttpClient(); //static readonly in real code
  
  var content = new StringContent(&quot;id_6=some text with Turkish characters öçşığüÖÇŞİĞÜ&quot;, Encoding.GetEncoding(&quot;ISO-8859-9&quot;), &quot;application/x-www-form-urlencoded&quot;);
  var response = httpClient.PostAsync(url, content).Result; //I know this is not a good way, I'll focus on it later
  var responseInString = response.Content.ReadAsStringAsync().Result;
  File.WriteAllText(&quot;c:\\temp\\a.htm&quot;, responseInString);
  </code></pre>
  <p>The web app returns me a html with some input values, including those posted by my code. Those form values posted by my code and those calculated using my values have bad Turkish characters, whereas the hardcoded submit button with Turkish characters look alright.</p>
  <p>The web app returns this html (truncated for simplicity) to my code:</p>
  <pre><code>&lt;!-- BELOW IS THE HARDCODED FORM FIELD WITH TURKISH CHARS OK! DISPLAYED AS: Programı Çağır --&gt;
  &lt;input type=&quot;submit&quot; value=&quot;Program&amp;#305; &amp;Ccedil;a&amp;#287;&amp;#305;r&quot; name=&quot;j_id_jsp_262293626_16&quot;/&gt;
  
  &lt;!-- IRRELEVANT HTML REMOVED --&gt;
  
  &lt;!-- BELOW IS THE OUTPUT FORM FIELD WITH CHAR ş BAD! DISPLAYED AS: some text with Turkish characters öç???üÖÇ???Ü --&gt;
  &lt;input type=&quot;text&quot; value=&quot;some text with Turkish characters &amp;ouml;&amp;ccedil;???&amp;uuml;&amp;Ouml;&amp;Ccedil;???&amp;Uuml;&quot; id=&quot;id_2&quot; name=&quot;id_2&quot;/&gt;
  
  &lt;!-- BELOW IS THE INPUT FORM FIELD WITH CHAR ş BAD! --&gt;
  &lt;input type=&quot;text&quot; value=&quot;some text with Turkish characters &amp;ouml;&amp;ccedil;???&amp;uuml;&amp;Ouml;&amp;Ccedil;???&amp;Uuml;&quot; id=&quot;id_6&quot; name=&quot;id_6&quot; /&gt;
  </code></pre>
  <p>Response headers look alright:
  <a href="https://i.stack.imgur.com/7zdGv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7zdGv.png" alt="Content headers from debug" /></a></p>
  <p>What can be wrong?</p>
  <p>EDIT: A similar code posting to a <a href="https://www.w3schools.com/html/html_forms.asp" rel="nofollow noreferrer">sample form</a> works ok:</p>
  <pre><code>    static readonly HttpClient httpClient = new HttpClient();
  
      [TestMethod]
      public void TestHttpClientForTurkish()
      {
          var data = new Dictionary&lt;string, string&gt;()
          {
              {&quot;fname&quot;, &quot;öçşığü&quot; },
              {&quot;lname&quot;, &quot;ÖÇŞİĞÜ&quot; }
          };
  
          var content = new FormUrlEncodedContent(data);
          var response = httpClient.PostAsync(&quot;https://www.w3schools.com/action_page.php&quot;, content).Result;
  
          var responseInString = response.Content.ReadAsStringAsync().Result;
          Assert.IsTrue(responseInString.Contains(&quot;öçşığü&quot;) &amp;&amp; responseInString.Contains(&quot;ÖÇŞİĞÜ&quot;));
      }
  </code></pre>