ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; ServicePointManager.Expect100Continue = true; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(txtRequestURL.Text); System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); request.Method = "POST"; request.Accept = @"application/json"; request.ContentType = @"application/json"; Byte[] byteArray = encoding.GetBytes(txtReq.Text); request.ContentLength = byteArray.Length; if (chkRequestHeader.Checked) { request.Headers.Add("X-API-KEY", txtXAPIKey.Text); } //request.Timeout = 1000 * Convert.ToInt32(txtResponseTimeOut.Text); string certificatePath = @"D:\Cert.cer"; request.ClientCertificates.Add(new X509Certificate(certificatePath)); txtLog.Text += "btnInvoke_Click()-Adding Certificates Process Completed with Certificate path:"+certificatePath + Environment.NewLine; using (Stream stm = request.GetRequestStream()) { stm.Write(byteArray, 0, byteArray.Length); } try { HttpWebResponse httpWebRes = (HttpWebResponse)request.GetResponse(); txtHTTPStatusCode.Text = Convert.ToString(httpWebRes.StatusCode); using (StreamReader responseReader = new StreamReader(httpWebRes.GetResponseStream())) { try { txtResponse.Text = responseReader.ReadToEnd(); } catch (Exception ex) { txtLog.Text += "btnInvoke_Click()-Fetching Response from Response Stream Failed with Exception: " + ex.Message + Environment.NewLine + " with Inner Exception:" + ex.InnerException + Environment.NewLine + " at Stack Trace: " + ex.StackTrace + Environment.NewLine; } responseReader.Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)