0

While invoking 3rd party web service from my web application I am receiving following exception and I want to find out what has gone wrong. The sercice request is working from postman.

System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream()

This is the code part that I have tried

ServicePointManager.Expect100Continue = true;
 ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(host);
req.Method = "POST";
req.ContentType = "application/json";
req.KeepAlive = true;
req.ProtocolVersion = HttpVersion.Version11;
//req.ClientCertificates.Add(new X509Certificate2(certPath, password));
Log.LogMessage(TracingLevel.DEBUG, "3.2)magensa cerificate added  : ");
// req.PreAuthenticate = true;
byte[] postBytes = Encoding.UTF8.GetBytes(postData);
req.ContentLength = postBytes.Length;
Stream postStream = req.GetRequestStream();
Log.LogMessage(TracingLevel.DEBUG, "3.3)magensa Request send  : ");
postStream.Write(postBytes, 0, postBytes.Length);
//postStream.Flush();
postStream.Close();
WebResponse response = (WebResponse)req.GetResponse();
string s = response.ToString();
Log.LogMessage(TracingLevel.DEBUG, "2) Web response : " + s);
StreamReader reader = new StreamReader(response.GetResponseStream());
String jsonresponse = "";
String temp = null;
while ((temp = reader.ReadLine()) != null)
{
    jsonresponse += temp;
}
Log.LogMessage(TracingLevel.DEBUG, "3)Magensa Response : " + jsonresponse);
XPD
  • 1,121
  • 1
  • 13
  • 26
  • 3
    Does this answer your question? [The request was aborted: Could not create SSL/TLS secure channel](https://stackoverflow.com/questions/2859790/the-request-was-aborted-could-not-create-ssl-tls-secure-channel) – InstilledBee Jan 10 '20 at 14:39
  • Use tools such as Wireshark to analyze the TLS/SSL handshake packets, and the cause should be obvious. – Lex Li Jan 10 '20 at 19:49

0 Answers0