title: C# HttpWebRequest Content-type not Changing
body: <p>In C# i need to POST some data to a web server using HTTP. I keep getting errors returned by the web server and after sniffing throught the data I dound that the problem is that thew Content-type header is still set to "text/html" and isn't getting changed to "application/json; Charset=UTF-8" as in my program. I've tried everything I can think of that might stop it getting changed, but am out of ideas.</p>
  
  <p>Here is the function that is causing problems:</p>
  
  <pre><code>private string post(string uri, Dictionary&lt;string, dynamic&gt; parameters)
      {
          //Put parameters into long JSON string
          string data = "{";
          foreach (KeyValuePair&lt;string, dynamic&gt; item in parameters)
          {
              if (item.Value.GetType() == typeof(string))
              {
                  data += "\r\n" + item.Key + ": " + "\"" + item.Value + "\"" + ",";
              }
              else if (item.Value.GetType() == typeof(int))
              {
                  data += "\r\n" + item.Key + ": " + item.Value + ",";
              }
          }
          data = data.TrimEnd(',');
          data += "\r\n}";
  
          //Setup web request
          HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(Url + uri);
          wr.KeepAlive = true;
          wr.ContentType = "application/json; charset=UTF-8";
          wr.Method = "POST";
          wr.ContentLength = data.Length;
          //Ignore false certificates for testing/sniffing
          wr.ServerCertificateValidationCallback = delegate { return true; };
          try
          {
              using (Stream dataStream = wr.GetRequestStream())
              {
                  //Send request to server
                  dataStream.Write(Encoding.UTF8.GetBytes(data), 0, data.Length);
              }
              //Get response from server
              WebResponse response = wr.GetResponse();
              response.Close();
          }
          catch (WebException e)
          {
              MessageBox.Show(e.Message);
          }
          return "";
      }
  </code></pre>
  
  <p>The reason i'm getting problems is because the content-type stays as "text/html" regardless of what I set it as.</p>
  
  <p>Thanks in advence.</p>