我想在Visual Studio 2013(Framework 4.5)中启用TLS 1.2,我在我的应用程序中使用了第三方Web api 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
我应该从Google的下面一行添加
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);
如何在c#代码中检查TLS 1.2是否正常工作