private HttpWebRequest request; private string SendRequest(string ip, string jsonRequest, int timeout, bool isOpen, string path, out string errorMessage) { string host = "https://" + jsonrpcServerIP + ":" + portNumber; Uri target = new Uri(host); try { request = (HttpWebRequest)WebRequest.Create(ip); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications); if (!isOpen) { request.CookieContainer = new CookieContainer(); request.CookieContainer.Add(new Cookie("sysauth", token, path, target.Host)); } request.ContentType = "application/json"; request.Method = "POST"; request.Timeout = timeout; request.KeepAlive = true; using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(jsonRequest); streamWriter.Flush(); streamWriter.Close(); } WebResponse response = request.GetResponse(); using (var streamReader = new StreamReader(response.GetResponseStream())) { jsonResponse = streamReader.ReadToEnd(); } } catch (Exception ex) { } } private bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) { return true; } else { return false; } }