C# 通过C向Salesforce提交POST请求
我的代码以前可以工作,但自从Salesforce将TLS 1.0加密协议更新为TLS 1.2后,它就停止工作了 请告诉我,在禁用TLS 1.0和启用TLS 1.2的情况下,为了使代码正常工作或向Salesforce发送信息,我应该进行哪些修改 下面是我的代码:C# 通过C向Salesforce提交POST请求,c#,asp.net,salesforce,tls1.2,C#,Asp.net,Salesforce,Tls1.2,我的代码以前可以工作,但自从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 = ""; HttpWebReques
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;
}
尝试将此行添加到代码中:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
这对我很有用。你应该先调试你的代码。没有调试信息,任何人都无法帮助您。正在向服务器发送什么?服务器返回什么?