在vb.net上使用PayPal PDT并获得:基础连接已关闭:发送中发生意外错误 [英] Using PayPal PDT with vb.net and getting: the underlying connection was closed: An unexpected error occurred on a send

查看:98
本文介绍了在vb.net上使用PayPal PDT并获得:基础连接已关闭:发送中发生意外错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PayPal沙箱中使用以下代码(vb.Net-3.5)已有2个月了,没有任何问题.现在抛出错误: 基础连接已关闭:发送

I have been using the following code (vb.Net-3.5) in the PayPal Sandbox for 2 months with no problems. Now it throws the error: The underlying connection was closed: An unexpected error occurred on a send

关于如何使它再次工作的任何想法.

Any ideas on what should be done to make it work again.

这是否与PayPal对沙箱中的SSL证书实施的更改有任何关系.这是在2016年1月18日之后开始发生的.我发现有关PayPal SSL证书更新的文章 https://www .paypal-knowledge.com/infocenter/index?page = content& id = FAQ1766

Could this have anything to do with the changes PayPal is implementing on the SSL Certificates in Sandbox. This started happening after 1/18/2016. I found this article about the PayPal SSL Certificate update https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1766

Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Collections.Generic
Imports System.Object
Imports System.Web
Imports System.Web.Configuration
Imports System.Web.Security
Imports System.Data
Imports System.Data.SqlClient
Imports System.Exception
Imports System.SystemException
Imports System.Threading.ThreadAbortException


Partial Class Payment
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        ' This is the initial start of program 
        Dim QString As String = ""
        Dim parcelID As String = ""
        Dim txID As String = ""

        ' Get Query string Variables
        QString = Request.ServerVariables("QUERY_STRING")
        parcelID = Request.QueryString("item_number")
        txID = Request.QueryString("tx")

        Try

            If Not String.IsNullOrEmpty(txID) Then


                ' Create a request using a URL that can receive a post. 
                ' Sandbox Version
                Dim PayPalWeb As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
                Dim PayPalID As String = "***********************************************************"
                ' Live Version
                'Dim PayPalWeb As String = "https://www.paypal.com/cgi-bin/webscr"
                'Dim PayPalID As String = ""

                Dim PayPalRequest As WebRequest
                ' Create POST data and convert it to a byte array.
                Dim postData As String = "cmd=_notify-synch" + _
                                         "&tx=" + txID + _
                                         "&at=" + PayPalID + _
                                         "&submit = PDT"

                Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)            
                Dim dataStream As Stream

                PayPalRequest = WebRequest.Create(PayPalWeb)
                ' Set the Method property of the request to POST.
                PayPalRequest.Method = "POST"
                ' Set the ContentType property of the WebRequest.
                PayPalRequest.ContentType = "application/x-www-form-urlencoded"
                ' Set the ContentLength property of the WebRequest.
                PayPalRequest.ContentLength = byteArray.Length
                ' Get the request stream.
                dataStream = PayPalRequest.GetRequestStream()  ' <===== Fails on this call
                ' Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length)
                ' Close the Stream object.
                dataStream.Close()
                ' Get the response.
                Dim PayPalResponse As WebResponse = PayPalRequest.GetResponse()

                ' Get the stream containing content returned by the server.
                dataStream = PayPalResponse.GetResponseStream()
                ' Open the stream using a StreamReader for easy access.
                Dim reader As New StreamReader(dataStream)
                ' Read the content.
                Dim responseFromServer As String = reader.ReadToEnd()

                ' Clean up the streams.
                reader.Close()
                dataStream.Close()
                PayPalResponse.Close()


            .......

推荐答案

我的问题是PayPal正在对其安全性进行更新的结果.
请参阅 https://www.paypal-knowledge.com/infocenter/index?page = content& id = FAQ1766

My problem was a result of the update PayPal is making to their security.
See https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1766

就我而言,我必须升级到.NEt Framework 4.5并包括以下内容:

In my case, I had to upgrade to .NEt Framework 4.5 and include the following:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

通话前 dataStream = PayPalRequest.GetRequestStream()

before the call dataStream = PayPalRequest.GetRequestStream()

这篇关于在vb.net上使用PayPal PDT并获得:基础连接已关闭:发送中发生意外错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆