Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过C向Salesforce提交POST请求_C#_Asp.net_Salesforce_Tls1.2 - Fatal编程技术网

C# 通过C向Salesforce提交POST请求

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

我的代码以前可以工作,但自从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;
}

尝试将此行添加到代码中:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

这对我很有用。

你应该先调试你的代码。没有调试信息,任何人都无法帮助您。正在向服务器发送什么?服务器返回什么?