title: Post JSON data to web API using object in C#
body: <p>I was able to write the code to perform GET operation from a web API. But, I'm not able to POST. I think the problem is with the JSON object. I'm able to POST if the parameters are sent via URL but I'm unable to do so if it's a JSON Object. Eg: The POST requires me to send ModelID, CustomerID via URL and ReferenceString as a JSON object.</p>
  
  <p><strong>Data to POST</strong></p>
  
  <blockquote>
    <p>ModelID = 3345</p>
    
    <p>CustomerID =1V34858493</p>
    
    <p>ReferenceID is a JSON string[]    </p>
    
    <p>[
      {
        "ReferenceId": "a123"
      }
    ]</p>
  </blockquote>
  
  <p>Main</p>
  
  <pre><code> static void Main(string[] args) 
      {
         // JavaScriptSerializer serializer = new JavaScriptSerializer();
  
          string patientServiceResponse = PostRequest( string.Format("https://url.com/api/{0}/{1}/taskOrders", 3345, "1V34858493"));
  
          Debug.Write(patientServiceResponse);
      }
  </code></pre>
  
  <p>POST Request</p>
  
  <pre><code>private static string PostRequest(string url)
      {
          HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
          httpWebRequest.ContentType = "application/json; charset=utf-8";
          httpWebRequest.Method = "POST";
          httpWebRequest.Accept = "application/json; charset=utf-8";
          string sContentType = "application/json";
  
          JObject oJsonObject = new JObject();
  
          oJsonObject.Add("ReferenceId", "a123");
  
          HttpClient oHttpClient = new HttpClient();
          var oTaskPostAsync = oHttpClient.PostAsync(url, new StringContent(oJsonObject.ToString(), Encoding.UTF8, sContentType));
  
          //return 
      }
  </code></pre>
  
  <p>Can you please correct me where I'm going wrong.</p>