来自asp.net中的PayPal沙盒的无效响应

时间:2018-07-17 06:17:57

标签: asp.net paypal-sandbox

我正试图从我的沙盒帐户接收交易详细信息。但是它总是返回无效响应。我进行了很多搜索,但是代码和模式在到处都与我使用的相同。字节数组中param的内容长度始终为0,我认为这可能是个问题。虽然我看到了沙盒贝宝上成功交易的详细信息,但仍收到无效响应。以下是我用来接收IPN消息的内容。

paymentconfirmation.aspx

 //Post back to either sandbox or live
            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            //string strLive = "https://www.paypal.com/cgi-bin/webscr";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);

            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength); //This always remains 0
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;

            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;

            //Send the request to PayPal and get the response

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();

            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd(); //always Invalid
            streamIn.Close();

            int iBookingId = -1;


            if (int.TryParse(Request.Form["item_number"], out iBookingId) == false)
            {
                if (int.TryParse(Request.QueryString["item_number"], out iBookingId) == false)
                {
                    return;
                }
            }

            if (strResponse == "VERIFIED")
            {
             //Continue inserting record
            }

0 个答案:

没有答案