gpt4 book ai didi

c# - Paypal 集成时出错

转载 作者:行者123 更新时间:2023-11-30 18:40:00 27 4
gpt4 key购买 nike

我尝试将 paypal 沙箱 与我在 asp.net 中的项目集成。

重定向到 paypal 沙箱工作非常好!您可以查看您的购物车!你可以付款!但问题是当 paypal 设置重定向到我的 Success.aspx 页面时!

我得到的错误是

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.0.101:808

我正在使用流编写器对象!

等一下,让我发布我的代码!

这甚至是 Success.aspx 的 page_load

   protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Used parts from https://www.paypaltech.com/PDTGen/
// Visit above URL to auto-generate PDT script

authToken = WebConfigurationManager.AppSettings["PDTToken"];

//read in txn token from querystring
txToken = Request.QueryString.Get("tx");


query = string.Format("cmd=_notify-synch&tx={0}&at={1}", txToken, authToken);

// Create the request back
string url = WebConfigurationManager.AppSettings["PayPalSubmitUrl"];
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);

// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = query.Length;

// Write the request back IPN strings
StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(query);
stOut.Close();

// Do the request to PayPal and get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();

// sanity check
Label2.Text = strResponse;

// If response was SUCCESS, parse response string and output details
if (strResponse.StartsWith("SUCCESS"))
{
PDTHolder pdt = PDTHolder.Parse(strResponse);
Label1.Text = string.Format("Thank you {0} {1} [{2}] for your payment of {3} {4}!",
pdt.PayerFirstName, pdt.PayerLastName, pdt.PayerEmail, pdt.GrossTotal, pdt.Currency);
}
else
{
Label1.Text = "Oooops, something went wrong...";
}
}
}

这句话造成错误!!

StreamWriter stOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);

发生这些类型的异常

    Exception Details: System.Net.Sockets.SocketException:
A connection attempt failed because the connected party did
not properly respond after a period of time,
or established connection failed because connected
host has failed to respond 192.168.0.101:808

最佳答案

首先,不要混用 PDT 和 IPN - 只需使用 IPN。进入 PayPal 管理并确保返回 URL 未在那里设置并且 PDT 未启用。

网上有一个 IPN 类(class)专门用于此目的 - 更多信息(注意:我自己的博文):

http://codersbarn.com/?tag=/paypal

http://paypalipnclass.codeplex.com/releases/view/31282

关于c# - Paypal 集成时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8974738/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com