【问题标题】:submit POST request to Salesforce through C#通过 C# 向 Salesforce 提交 POST 请求
【发布时间】:2017-07-07 12:44:04
【问题描述】:

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

【问题讨论】:

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

标签: c# asp.net salesforce tls1.2


【解决方案1】:

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

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

它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-05
    • 2018-11-26
    • 2017-02-18
    • 2011-09-10
    • 1970-01-01
    • 2020-02-28
    • 2016-03-21
    • 1970-01-01
    相关资源
    最近更新 更多