title: PUT REST request with C#
body: <p>I need to do a PUT request with header <code>IDENTITY_KEY</code>.</p>
  
  <p>Specifically, I need to do the following with C#, which I have now done with <code>curl</code>:</p>
  
  <pre><code>curl --request PUT \
  --header IDENTITY_KEY: c956c302086a042dd0426b4e62652273e05a6ce74d0b77f8b5602e0811025066 \
  --header Content-type: application/json \
  --data @data.txt http://192.168.1.200:8081/data/testApp_provider/RE0025
  </code></pre>
  
  <p>Where <code>data.txt</code> contains the JSON:</p>
  
  <pre><code>{"observations":[{
      "value":"10.1"
     },{
      "value":"11.2",
      "timestamp":"20/12/2015T12:34:45"
     },{
      "value":"12.3",
      "timestamp":"20/12/2015T10:34:45"
     }
  ]}
  </code></pre>
  
  <p>How can I do that?</p>
  
  <p>I tried with this code but it has not worked:</p>
  
  <pre><code>using System;
  using System.IO;
  using System.Net;
  
  namespace ConsoleApplication6
  {
      class Program
      {
          static void Main(string[] args)
          {
              var request = WebRequest.Create("http://192.168.1.200/data/testApp_provider/RE0025");
              request.Method = "PUT";
              request.ContentType = "application/json; charset=utf-8";
              request.Headers["IDENTITY_KEY"] = "c956c302086a042dd0426b4e62652273e05a6ce74d0b77f8b5602e081102506";
  
                  using (var writer = new StreamWriter(request.GetRequestStream()))
              {
                  var serializer = new JavaScriptSerializer();
                  var payload = serializer.Serialize(new
                  {
                      value = "97",
                      timestamp = "20 / 12 / 2015T12:34:45"
  
                  });
                  writer.Write(payload);
              }
  
              using (var response = request.GetResponse())
              using (var reader = new StreamReader(response.GetResponseStream()))
              {
                  string result = reader.ReadToEnd();
  
              }
          }
      }
  </code></pre>