Как включить TLS 1.2 в Visual Studio 2013 (Framework 4.5) - PullRequest
0 голосов
/ 10 апреля 2019

Я хочу включить TLS 1.2 в Visual Studio 2013 (Framework 4.5), я использую сторонний URL-адрес веб-приложения в своем приложении, поэтому сегодня я получил письмо от владельца API, как показано ниже.

If you are using any of the following programming languages, you need to update them to effectively communicate with our API: 
Java 6u45

Java 7u25

OpenSSL 0.9.8y

.NET 4.5 and below

.NET 4.5 (settings should be changed to enable TLS 1.2)

So i am using .NET 4.5

Как я понял из гугла снизу надо добавить строку

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

Я добавил вышеуказанную строку кода перед HttpWebRequest

var updationapi = "https://recruit.zoho.com/recruit/private/xml/Candidates/addRecords?authtoken=0554449f9f4790344c644e344abd4404df435ff8ab&scope=recruitapi&duplicateCheck=1&version=2";
 //i have added this new line for TLS 1.2
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(updationapi);
request.Method = "Post";
request.KeepAlive = true;
request.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.UseDefaultCredentials = true;
request.Credentials = new NetworkCredential("kk@dfsf.com", "pass123", "https://recruit.zoho.com/");
request.ContentType = "appication/xml";
//new code sending data from xlm body not api url comments above
Stream xmlDataStream = request.GetRequestStream();
byte[] bytes = Encoding.ASCII.GetBytes("xmlData=" + HttpUtility.UrlEncode(xmlString.ToString()));
xmlDataStream.Write(bytes, 0, bytes.Length);
xmlDataStream.Close();
//new code end
//request.Headers.Add("Content-Type", "appication/xml");
request.ContentType = "application/x-www-form-urlencoded";

HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string myResponse = "";
using (System.IO.StreamReader sr = new System.IO.StreamReader(response.GetResponseStream()))
                {
                    myResponse = sr.ReadToEnd();
                }
                Response.Write(myResponse);

Как проверить, работает ли TLS 1.2 в коде c #

...