Запрос был прерван: не удалось создать защищенный канал SSL/TLS
Он работал хорошо до недели, но теперь он показывает следующую ошибку. Я пробовал следующее, но бесполезно.
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
поэтому предложите мне с возможным решением
public string HttpCall(string NvpRequest) //CallNvpServer
{
string url = pendpointurl;
//To Add the credentials from the profile
string strPost = NvpRequest + "&" + buildCredentialsNVPString();
strPost = strPost + "&BUTTONSOURCE=" + HttpUtility.UrlEncode(BNCode);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
// allows for validation of SSL conversations
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Timeout = Timeout;
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
try
{
using (StreamWriter myWriter = new StreamWriter(objRequest.GetRequestStream()))
{
myWriter.Write(strPost);
}
}
catch (Exception e)
{
/*
if (log.IsFatalEnabled)
{
log.Fatal(e.Message, this);
}*/
}
//Retrieve the Response returned from the NVP API call to PayPal
HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();
string result;
using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
}
//Logging the response of the transaction
/* if (log.IsInfoEnabled)
{
log.Info("Result :" +
" Elapsed Time : " + (DateTime.Now - startDate).Milliseconds + " ms" +
result);
}
*/
return result;
}
Ответы
Ответ 1
Я просто столкнулся с этой проблемой в своей тестовой среде (к счастью, мои текущие платежи проходят). Я исправил это, изменив:
public PayPalAPI(string specialAccount = "")
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls;
к
public PayPalAPI(string specialAccount = "")
{
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
Они отключили поддержку SSL3 некоторое время назад: https://www.paypal.com/uk/webapps/mpp/ssl-security-update, в частности, указав
Убедитесь, что вы подключаетесь к конечным точкам PayPal, используя TLS 1.0 или 1.2 (не все конечные точки API в настоящее время поддерживают TLS 1.1).
Их последнее обновление (спасибо для обновления комментариев от @awesome):
PayPal обновляет свои услуги, требуя TLS 1.2 для всех HTTPS соединения. В это время PayPal также потребует HTTP/1.1 для всех соединения... Чтобы избежать сбоев в обслуживании, вы должны убедиться, что ваши системы готовы к этому изменению до 17 июня 2016 г.
Ответ 2
Действительно, изменение SecurityProtocolType.Tls устраняет проблему, если вы работаете в VS с инфраструктурой ниже 4,5, вы не сможете ее изменить, вам нужно обновить VS до максимальная версия 2012/2013/2015, чтобы изменить его.
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType Tls12;.
Ответ 3
Добавьте следующий код в свой global.asax или перед вызовом (HttpWebRequest) WebRequest.Create(url);
protected void Application_Start()
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// ...
}
Это было вызвано тем, что PayPal меняет свое шифрование на TLS вместо SSL. Это уже было обновлено в средах Sandbox, но еще не включено.
Подробнее:
https://devblog.paypal.com/upcoming-security-changes-notice/