場景描述: 我公司的網站之前就已經開發好了下單支持paypal支付,當然,這個是其他同事開發的。前段時間,主管讓我在另一個場景開發支持使用paypal支付,當時花了些時間看看關於paypal代碼,然后就嘗試着寫了,雖然代碼不多,很快就寫完了。不過接下來遇到的問題真的很頭疼,在沙盒模式下調試,一直會跳出異常:請求被中止: 未能創建 SSL/TLS 安全通道。遇到這個問題的時候,也百度或者google了,嘗試了很多種方法,還是不能解決掉這個問題,花了幾天的時間,現在想想也是醉了,不過開發的就是要不斷的嘗試。最后在github上面找到了解決方案,https://github.com/paypal/TLS-update/tree/master/net/TlsCheck,希望可以幫到 需要的朋友。在創建請求地址的前面加了這句代碼就可以了:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(serverURL); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; strNewValue = "cmd=_notify-synch&tx=" + System.Web.HttpContext.Current.Request.QueryString["tx"] + "&at=" + PayPalParameter.BusinessToken;