0

I am trying to write an https Post with the data duration=300. I am new to C# and am writing in a sandbox for another program called Crestron Simpl#. If anyone could help point me in the right direction for adding the data to the Post. Thanks

    public void post(String postVar)
    {
        try
        {
            var httpsSet = new HttpsClient();
            httpsSet.KeepAlive = false;
            httpsSet.Accept = "application/xml";
            httpsSet.UserName = username;
            httpsSet.Password = password;
            httpsSet.HostVerification = false;
            httpsSet.PeerVerification = false;
            HttpsClientRequest sRequest = new HttpsClientRequest();
            sRequest.RequestType = RequestType.Post;
            sRequest.Url.Parse("https://" + ipaddress + postVar);
            HttpsClientResponse response = httpsSet.Dispatch(sRequest);
            string responseRx = response.ContentString;
            ushort iRepsonse = myRx(responseRx); 
        }
        catch (Exception e)
        {
            CrestronConsole.PrintLine(String.Format("{0} exception", e.Message));                
        }       
    } 

1 Answers1

0

Here's a sample C# snippet for a PUT request.

HttpWebRequest HttpWReq = (HttpWebRequest) WebRequest.Create("http:\\YourDomain.com");
ASCIIEncoding Encoding = new ASCIIEncoding();
byte[] data = Encoding.GetBytes("Put you data here");
HttpWReq.Method = "PUT";
HttpWReq.ContentType = "Enter your MIME type";
HttpWReq.ContentLength = data.Length;

//Then when you actually want to write the request, perform these functions:
Stream NewStream = HttpWReq.GetRequestStream();
NewStream.Write(data, 0, data.Length);
NewStream.Close();

You can read more into other answers here.

Community
  • 1
  • 1
Loufs
  • 1,596
  • 1
  • 14
  • 22