title: C# WebClient - very simple post json to PHP server
body: <p>My server works with PHP and use <code>$_POST</code> variable. My Client use C#.</p>
  
  <p>With <code>ContentType = application/json</code>, i need to use <code>$post = json_decode(file_get_contents('php://input'), true);</code> in PHP server</p>
  
  <p>But with <code>ContentType = application/x-www-form-urlencoded</code> the <code>$_POST</code>variable is a array with the json string like <code>[ **the json variable as string** ]</code></p>
  
  <p>What is wrong with my code when i use <code>application/x-www-form-urlencoded</code></p>
  
  <hr>
  
  <p>Exemple:</p>
  
  <pre><code>var post = new Dictionary&lt;string, object&gt;
  {
      ["key1"] = "data1",
      ["key2"] = new List&lt;string&gt;{ "data2", "data3" }
  };
  </code></pre>
  
  <p>Get <code>[  "[\"key1\"] = \"data1\" ... \"data3\"]"  ]</code> as <code>$_POST</code> (1 array with 1 string)</p>
  
  <hr>
  
  <p>The C# client:</p>
  
  <pre><code>var post = new Dictionary&lt;string, object&gt;
  {
      ["key1"] = "data1",
      ["key2"] = new List&lt;string&gt;{ "data2", "data3" }
  };
  var url = "https://urlrandom.com";
  var method = "POST";
  
  using (var webClient = new WebClient())
  {
      webClient.Headers[HttpRequestHeader.UserAgent] = "Other";
      webClient.Headers[HttpRequestHeader.Accept] = "application/json";
      webClient.Headers[HttpRequestHeader.ContentType] = ; // "application/json" or "application/x-www-form-urlencoded"
  
      var dataString = JsonConvert.SerializeObject(post);
      var bytes = Encoding.UTF8.GetBytes(dataString);
      var jsonBytes = webClient.UploadData(url, method, bytes);
      var jsonString = Encoding.UTF8.GetString(jsonBytes);
      var json = JsonConvert.DeserializeObject&lt;Dictionary&lt;string, object&gt;&gt;(jsonString);
  
      return json;
  }
  </code></pre>
  
  <hr>
  
  <p>The PHP server:</p>
  
  <pre><code>&lt;?php 
  echo array_key_exists($_POST, "key1"); /* false with application/x-www-form-urlencoded */
  exit();
  ?&gt;
  </code></pre>