title: Send post data through winform
body: <p>I have a device hooked up through ethernet on a static IP. There is an html interface to communicate with the device. The interface monitors the io of the device. It has configuration settings to change things such as the IP Address, Subnet Mask, MAC Address, and Default Gateway. It is also how you send commands to the device. </p>
  
  <p>I want to make a C# Windows form to represent only the functionality I need. Where I am getting caught up is in sending the commands from the form.</p>
  
  <p>The html interface is using jquery to send commands back to the device.</p>
  
  <p><code>function sendCMD(indata) {$.post("setcmd.cgx", indata, function (data) {});</code></p>
  
  <p><code>sendCMD({ver : "1",cmd : "abf"});</code></p>
  
  <p>I am currently trying to send the post back through a WebRequest, which is just returning the html of URI. I have come to the conclusion that I shouldn't be using WebRequest for this and/or I am sending the post data incorrectly.</p>
  
  <p>What I currently Have:</p>
  
  <pre><code>private void btnAimingBeamOn_Click(object sender, EventArgs e)
      {
          string postData = "\"setcmd.cgx\", {\n\rver : \"1\", \n\rcmd : \"abn\"\n\r}, function (data) {}";
          byte[] byteArray = Encoding.UTF8.GetBytes(
  
          Uri target = new Uri("http://192.168.3.230/index.htm"); 
          WebRequest request = WebRequest.Create(target);
          request.Method = "POST";
          request.ContentType = "application/x-www-form-urlencoded";
          request.ContentLength = byteArray.Length;
  
          Stream dataStream = request.GetRequestStream();
          dataStream.Write(byteArray, 0, byteArray.Length);
          dataStream.Close();
  
          WebResponse response = request.GetResponse();
          txtABNStatus.Text = (((HttpWebResponse)response).StatusDescription);
  
          dataStream = response.GetResponseStream();
          StreamReader reader = new StreamReader(dataStream);
          string responseFromServer = reader.ReadToEnd();
          txtABNResponse.Text = (responseFromServer);
  
          reader.Close();
          response.Close();
          dataStream.Close();
      }
  </code></pre>
  
  <p>Any help with the proper method of sending the post and how to format the post data would be most appreciated.</p>