【发布时间】:2012-04-14 21:33:37
【问题描述】:
我正在尝试测试我的贝宝应用程序并将我的贝宝 notify_url 指定为 www.xx.com/paypal.aspx。我应该得到沙盒贝宝的回应。但是我在 paypal.aspx 页面上没有得到任何东西。我的响应处理代码是:
protected void Page_Load(object sender, EventArgs e)
{
string connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;
con = new SqlConnection(connStr);
con.Open();
//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);
string strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
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();
streamIn.Close();
if (strResponse == "VERIFIED")
{
//Insert statement
}
else if (strResponse == "INVALID")
{
//UPDATE YOUR DATABASE
StreamWriter swr = new StreamWriter(Server.MapPath("Textfile.txt"));
swr.WriteLine("---- not verified(" + DateTime.Now.ToString() + ")--");
swr.Dispose();
}
else
{ //UPDATE YOUR DATABASE
//TextWriter txWriter = new StreamWriter(Server.MapPath("../uploads/") + Session["orderID"].ToString() + ".txt");
//txWriter.WriteLine("Invalid");
////log response/ipn data for manual investigation
//txWriter.Close();
}
付款已完全处理。我也被引导到感谢页面。请帮忙
谢谢
【问题讨论】:
-
首先打开数据库,忘记使用,关闭。为什么你有它呢?其次,此代码的实际问题是什么?因为您说根本没有调用,所以问题在于您发送到贝宝的网址。您希望从哪里调用它?从 asdn rooter 后面的本地计算机,从静态 ip 上的服务器?从哪里来?
-
我已经打开了数据库连接。代码不是问题,这是我应该获得 IPN 响应的页面。但是我刚刚检查了 IPN 历史记录,那里的状态是 FAILED,尽管我的交易正在发生。我很抱歉问题的框架很差。它将从服务器调用。
-
您以错误的方式打开数据库,却忘记关闭它 - 代码错误。现在,这个页面是否被调用?
-
我是一个初学者,你能告诉我如何在打开数据库时改进我的代码。是的,我已经在 IPN 通知 url 中指定了这个页面。
-
只在你要使用它的时候打开和关闭数据库,如果你要使用它,使用“using(con = new SqlConnection(connStr)){ }”看例子@ 987654321@
标签: asp.net c#-4.0 paypal-ipn paypal-sandbox