using (var client = ComHttpClient.GetHttpClient()) { ServicePointManager.Expect100Continue = true; ServicePointManager.DefaultConnectionLimit = 9999; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; client.BaseAddress = new Uri(CommReqURL); // Add an Accept header for JSON format. client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, operation); httpRequestMessage.Headers.Add("ServeTracingData", GenerateTraceId()); var jsonSettings = new JsonSerializerSettings { DateFormatHandling = DateFormatHandling.MicrosoftDateFormat }; var requestString = JsonConvert.SerializeObject(ocapRequest, jsonSettings); httpRequestMessage.Content = new StringContent(requestString, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; try { response = await client.SendAsync(httpRequestMessage); } catch(Exception ex) { } public static HttpClient GetHttpClient() { ServicePointManager.Expect100Continue = true; ServicePointManager.DefaultConnectionLimit = 9999; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; if (!bool.Parse(ConfigurationManager.AppSettings["abc"])) return new HttpClient(); var commCertSubject = ConfigurationManager.AppSettings["Certificate"]; WebRequestHandler handler = new WebRequestHandler(); X509Certificate2 certificate = GetStoreCertificate(commCertSubject); handler.ClientCertificates.Add(certificate); return new HttpClient(handler); }
The above piece of code I'm using to consume a web api but recently we upgraded .net framework to 4.7.1 on the server and I get an error "the request was aborted could not create ssl tls secure channel " .
My Project target framework is 4.7.1 too. The weird thing is my colleague don't get this message but I get this. I'm not sure what's wrong. Also, he don't have the below piece of code
ServicePointManager.Expect100Continue = true; ServicePointManager.DefaultConnectionLimit = 9999; ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
I searched on internet and found the solution above piece of code but this is not working for me :(. I'm scratching my head since a day. Please help!