title: How to send POST with form data in C#
body: <p>I am trying to make a program that requests my website with a username, password, hardware ID and a key in POST.</p>
  <p>I have this code here that should send a POST request to my website with that form data, but when it sends, my webserver reports back that it didn't recieve the POST data</p>
  <pre><code>try
              {
                  string poststring = String.Format(&quot;username={0}&amp;password={1}&amp;key={2}&amp;hwid={3}&quot;, Username, Password, &quot;272453745345934756392485764589&quot;, GetHardwareID());
                  HttpWebRequest httpRequest =
      (HttpWebRequest)WebRequest.Create(&quot;mywebsite&quot;);
  
                  httpRequest.Method = &quot;POST&quot;;
                  httpRequest.ContentType = &quot;application/x-www-form-urlencoded&quot;;
  
                  byte[] bytedata = Encoding.UTF8.GetBytes(poststring);
                  httpRequest.ContentLength = bytedata.Length;
  
                  Stream requestStream = httpRequest.GetRequestStream();
                  requestStream.Write(bytedata, 0, bytedata.Length);
                  requestStream.Close();
  
  
                  HttpWebResponse httpWebResponse =
                  (HttpWebResponse)httpRequest.GetResponse();
                  Stream responseStream = httpWebResponse.GetResponseStream();
  
                  StringBuilder sb = new StringBuilder();
  
                  using (StreamReader reader =
                  new StreamReader(responseStream, System.Text.Encoding.UTF8))
                  {
                      string line;
                      while ((line = reader.ReadLine()) != null)
                      {
                          sb.Append(line);
                      }
                  }
  
                  return sb.ToString();
              }
              catch (Exception Error)
              {
                  return Error.ToString();
              }
  </code></pre>
  <p>If someone could help me, I would really appreciate it.</p>