C#VS2008 HttpsClient发布数据的操作方法

本文关键字:数据 操作方法 HttpsClient 布数据 C#VS2008 | 更新日期: 2023-09-27 17:59:05

我正在尝试编写一个数据持续时间为300的https Post。我是C#的新手,正在为另一个名为Crestron Simpl#的程序编写沙盒。如果有人能帮我把数据添加到《华盛顿邮报》的正确方向。感谢

    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));                
        }       
    } 

C#VS2008 HttpsClient发布数据的操作方法

下面是PUT请求的C#代码片段示例。

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();

你可以在这里阅读更多其他答案。