2014-03-25 71 views
0

成功付款後,它重定向我的成功URL,但我沒有得到IPN的迴應。沒有得到IPN迴應

下面是notifypage.aspx.cs頁面代碼:

protected void Page_Load(object sender, EventArgs e) 
{ 

    //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; 

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

    //Send the request to PayPal and get the response 
    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") 
    { 

     File.WriteAllText(HttpContext.Current.Server.MapPath("~") + @"\Notify.txt", "Student1111" + Environment.NewLine + "----------------------------------------" + Environment.NewLine); 
    } 
    else if (strResponse == "INVALID") 
    { 
     File.WriteAllText(HttpContext.Current.Server.MapPath("~") + @"\Notify.txt", "Problem with payment : " + Environment.NewLine + "----------------------------------------" + Environment.NewLine); 
    } 
    else 
    { 
     File.WriteAllText(HttpContext.Current.Server.MapPath("~") + @"\Notify.txt", "not any" + Environment.NewLine + "----------------------------------------" + Environment.NewLine); 
    } 
} 

所以請幫助我,我怎麼能拿回來的IPN迴應?

+0

是否啓用IPN在商家的賬戶,並添加了IPN的網址? – IrishChieftain

回答

-1

Paypal IPN響應只調用服務器域,如果您在本地主機上嘗試它,它將不會調用您的通知URL頁面。

+0

嗨,我已經在notify_url變量..不是本地主機url添加了實時url .. –

+0

@JayeshTanna我只編輯回答(文本是代碼格式)。 – slavoo

+0

是的,但如果你從本地主機測試它不會工作,你可以在服務器上傳後測試它 –

0

您應該測試的工作你IPN Listner這裏

​​

+0

@G Ravinder我也嘗試過在ipn模擬器中,但它有這樣的錯誤:「由於HTTP錯誤,我們無法發送IPN:500:內部服務器錯誤」 –

+0

請檢查您的IPN列表程序代碼。它正在生成一個例外 可能的原因: 您可能正在讀取請求中不存在的變量 請使用Try {} Catch {}並將郵件保存或發送給self,ipn listner中的例外的詳細信息測試錯誤 –