我的代码之前曾用过,但自从Salesforce从TLS 1.0加密协议更新到TLS 1.2后,它停止了工作。
是否可以告诉我,为了使我的代码能够工作或向禁用TLS 1.0并启用TLS 1.2的Salesforce发送信息,我应该做些什么修改。
这是我的代码:
public static string WRequest(string URL, string method, string postData)
{
string responseData = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
request.Accept = "*/*";
request.AllowAutoRedirect = true;
request.UserAgent = "http_requester/0.1";
request.Timeout = 60000;
request.Method = method;
if (request.Method == "POST")
{
request.ContentType = "application/x-www-form-urlencoded";
UTF8Encoding encodingutf8 = new UTF8Encoding();
byte[] postByteArray = encodingutf8.GetBytes(postData);
request.ContentLength = postByteArray.Length;
Stream postStream = request.GetRequestStream();
postStream.Write(postByteArray, 0, postByteArray.Length);
postStream.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(responseStream);
responseData = myStreamReader.ReadToEnd();
}
response.Close();
return responseData;
}
答案 0 :(得分:-1)
尝试将此行添加到您的代码中:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
它对我有用。