C# paypal集成时出错
我曾尝试将C# paypal集成时出错,c#,asp.net,sandbox,C#,Asp.net,Sandbox,我曾尝试将paypal沙盒与我在asp.net中的项目集成 重定向到贝宝沙盒工作非常好!你可以查看你的购物车!你可以付款!但问题是当paypal设置重定向到my Success.aspx页面时 我得到的错误是 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because
paypal沙盒
与我在asp.net中的项目集成
重定向到贝宝沙盒工作非常好!你可以查看你的购物车!你可以付款!但问题是当paypal设置重定向到my 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的页面
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 admin,确保返回URL未设置在那里,并且未启用PDT 网上有一个IPN课程可用于此目的-更多信息(注意:我自己的博客帖子):
发帖子可能非常棘手。您是否使用Fiddler2或其他请求捕获程序来捕获请求?我会去网站,尝试做一个测试提交的付款,看看后的要求,你也可以捕捉到它在大多数浏览器现在。分析它。检查您的返回URL-看起来您缺少端口号后面的零?也要遵循Algothym的建议,检查完整的请求URL(如果必须,请将其写入输出)