我們有一個使用.Net Framework 4.0和IIS 7的網站。 在Paypal的最後更新之後,我們的IPN處理程序不再工作。因爲我們使用的是.NET Framework 4.0中 The request was aborted: Could not create SSL/TLS secure channel sandbox account 所以我們加入下一行:我們有這個錯誤獲取貝寶迴應TLS 1.2 .Net Framework 4.0
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
現在我們有另一個錯誤: 基礎連接已關閉:上一個發送發生意外的錯誤。
處理該響應的類是基於下面的例子: https://mvcsamples.svn.codeplex.com/svn/trunk/Kona.Web/Controllers/PayPalController.cs
現在前行加入後看起來是這樣的:
private string GetPayPalResponse(Dictionary<string, string> formVals, bool useSandbox)
{
string paypalUrl = useSandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
: "https://www.paypal.com/cgi-bin/webscr";
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(paypalUrl);
// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
StringBuilder sb = new StringBuilder();
sb.Append(strRequest);
foreach (string key in formVals.Keys)
{
sb.AppendFormat("&{0}={1}", key, formVals[key]);
}
strRequest += sb.ToString();
req.ContentLength = strRequest.Length;
//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://urlort#");
//req.Proxy = proxy;
//Send the request to PayPal and get the response
string response = "";
using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
{
streamOut.Write(strRequest);
streamOut.Close(); linea = 10;
using (StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
{
response = streamIn.ReadToEnd();
}
}
return response;
}
唯一的例外是在此行中提出:
using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
我們不確定我們是否可以使用.NET Framework 4.0進行PayPal工作。據說可以使用我們添加的行。但沒有工作。也許在代碼或IS 7中需要做更多的更改,但我們找不到例子。
謝謝你的幫助。
編輯:
我差點忘了提,該項目使用Visual Studio 2010中哪裏有沒有在.NET Framework 4.5開發的。
編輯2:
我調查的問題,我發現,我們的服務器Windows Server 2008不支持TLS 1.2(看錶): https://blogs.msdn.microsoft.com/kaushal/2011/10/02/support-for-ssltls-protocols-on-windows/ 但在那之後,我發現這個新的更新2016年所有版本的SQL Server。 https://blogs.msdn.microsoft.com/sqlreleaseservices/tls-1-2-support-for-sql-server-2008-2008-r2-2012-and-2014/ http://blogs.sqlsentry.com/aaronbertrand/tls-1-2-support-read-first/
但最後我的老闆因某些原因決定不更新使用新的更新或使用寄存器方法服務器。
所以我不能證明任何解決方案解決問題。抱歉,添麻煩了。
根據此頁 [鏈接](https://msdn.microsoft.com/it-it/library/system.net.securityprotocoltype(v = vs.100).aspx) TLS 1.2和TLS 1.1是在Framework 4.0中不受支持 – FabioThorin
您是否找到針對此問題的解決方案?我們使用.NET 4.6.1,因此指定Tls |並不是問題Tls11 | Tls12用於ServicePointManager.SecurityProtocol。在Tls12設置後,我正在處理第二個異常「底層連接已關閉」。白日虛耗。無論我嘗試什麼,我都會得到這個例外。顯然還有其他的東西需要設置或配置,但是什麼? – Alex