title: Adding Headers and Post data in HTTP Request in C#
body: <p>I am trying to integrate a API. Where document maintained that i need to add below Attribute headers for POST. But i don't know why my code for POST. I feel i am doing a silly mistake. Can you please take a look and help me. </p>
  
  <p><strong>Attribute to Add In Header</strong>  </p>
  
  <pre><code>  clientId   
    SecurityToken 
    Content-Type 'application/json'
    Accept       `application/json
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public string AddOrder(string url, string stringOrder, string bigApiUserID, string BigApiKey)
      {
  
          try
          {
              string responseStr = "";
              HttpStatusCode statusCode;
              WebRequest request = WebRequest.Create(url);
              request.Credentials = new NetworkCredential(bigApiUserID, BigApiKey);
              request.Method = "POST";
              byte[] bytes;
              bytes = System.Text.Encoding.ASCII.GetBytes(stringOrder);
  
              request.Headers.Add("SecurityToken", BigApiKey);
              request.ContentType = "application/json";
  
              request.ContentLength = bytes.Length;
              Stream requestStream = request.GetRequestStream();
              requestStream.Write(bytes, 0, bytes.Length);
              requestStream.Close();
              HttpWebResponse response;
              response = (HttpWebResponse)request.GetResponse();
              statusCode = response.StatusCode;
              if (Convert.ToString(response.StatusCode) == "OK")
              {
                  Stream responseStream = response.GetResponseStream();
                  responseStr = new StreamReader(responseStream).ReadToEnd();
                  return responseStr;
              }
              return responseStr;
          }
          catch (WebException e)
          {
  
               string responseStr = "";
              using (WebResponse response = e.Response)
              {
                  HttpWebResponse httpResponse = (HttpWebResponse)response;
                  responseStr = httpResponse.StatusCode.ToString();
                  using (Stream data = response.GetResponseStream())
                  {
                      responseStr = new StreamReader(data).ReadToEnd();
                  }
              }
              ErrorLog errLog = new ErrorLog();
              errLog.LogsWrite(e, Path.GetDirectoryName(Application.ExecutablePath));
              return responseStr;
          }
      }
  </code></pre>