asp.net - 支付宝底层连接被关闭

标签 asp.net vb.net paypal

我正在尝试从 paypal 沙箱环境中获取响应以测试从 paypal 返回的变量。我现在使用的是 asp.net 和 vb.net,代码在实时 paypal url 上运行良好,但由于某些奇怪的原因在本地 url 上运行不正常。

我想使用沙盒环境进行本地测试,但出现以下错误。

An exception of type 'System.Net.WebException' occurred in System.dll but was not handled in user code

Additional information: The underlying connection was closed: An unexpected error occurred on a send.

现在代码可以运行了

 Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.paypal.com/cgi-bin/webscr"), HttpWebRequest)

我以为我改变的只是这个

  Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"), 

主要代码

 Dim req As HttpWebRequest = CType(WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr"), HttpWebRequest)
    'Set values for the request back
    req.Method = "POST"
    req.ContentType = "application/x-www-form-urlencoded"
    Dim Param() As Byte = Request.BinaryRead(HttpContext.Current.Request.ContentLength)
    Dim strRequest As String = Encoding.ASCII.GetString(Param)
    strRequest = strRequest + "&cmd=_notify-validate"
    req.ContentLength = strRequest.Length

    'Send the request to PayPal and get the response
    Dim streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
    streamOut.Write(strRequest)
    streamOut.Close()
    Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
    Dim strResponse As String = streamIn.ReadToEnd()
    streamIn.Close()

    'Assign payment variables 
    strOrderNo = HttpContext.Current.Request("item_number")
    strGross = HttpContext.Current.Request("mc_gross")

编辑 2 经过进一步调查,这似乎是 paypal 更改其沙箱的方式,但我无法将我的应用程序升级到 4.5 以仅使用沙箱,他们的任何选项对我开放吗?根据这个堆栈

Using PayPal PDT with vb.net and getting: the underlying connection was closed: An unexpected error occurred on a send

建议更改此行以使用 Tsl12,但这不是我网站中的一个选项,我目前无法将其升级为日常使用的网站。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

为什么代码在实时环境中工作正常为什么 paypal 改变了他们的沙箱来做到这一点?

最佳答案

对于其他苦苦挣扎的人,我发现了如何使用以下 hack 来解决此问题

Const _Tls12 As SslProtocols = DirectCast(&HC00, SslProtocols)
Const Tls12 As SecurityProtocolType = DirectCast(_Tls12, SecurityProtocolType)
ServicePointManager.SecurityProtocol = Tls12

感谢 How to implement Security Protocols TLS 1.2 in .Net 3.5 framework 的出色操作

任何人都可以告诉我使用上述 hack 的影响是否会成为 future 的证据。

关于asp.net - 支付宝底层连接被关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45835490/

相关文章:

ios - curl 到 AFNetworking?

ios - iOS 中捐赠按钮的 Paypal 集成

c# - .Net 4.0 在使用 Attributes.Add 时编码单引号

vb.net - 将 Nullable 属性默认值设置为 Nothing 无法正常工作

regex - 取消 KeyUP 事件的处理程序?网络

asp.net - 中继器中的下拉列表,选定的索引更改后不起作用

php - 使用 PayPal IPN 验证付款金额(美元 + 其他),无需运费或税费

c# - 如何将 int 转换为字节数组?

asp.net - 使用 ASP.net (Vb.net) 将上传的 Excel 文档中的数据插入数据库

c# - 获取DataPager控件中点击的页面数