Using POST GET request by RestClient with SSL, TLS12

This is sample code how to POST / GET request using RestClient with SSL, TLS



private string PostXml(string xml, string DetinationURL)
        {
            string result = "";
            try
            {

                string StartTime = "BeginTime: " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
                DetinationURL = DetinationURL + "?" + xml;
                var client = new RestClient(DetinationURL);
                var request = new RestRequest(Method.GET);
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => { return errors == SslPolicyErrors.None; };
                request.AddHeader("cache-control", "no-cache");
                client.Timeout = 1000 * 40; //40 seconds
                IRestResponse response = client.Execute(request);
                result = response.Content;              
                client.ClearHandlers();
                request = null;
                client = null;

            }
            catch (Exception ex)
            {
            }
            return result;
        }
Reactions

Post a Comment

0 Comments