locked
PayPal IPN - Listener not sending request back to PayPal - asp.net RRS feed

  • Question

  • User95943963 posted

    Hi All,

    Spent the last two days trying to sort this out. It's code I have used many times before with success, but it is failing now. I am working with ASP.NET 4.0 on IIS6. I am working with the IPN simulator. Here is what is happening. If I point the simulator to my listener without any code in it I get A-OK!

    IF I add the following code:

    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;
    EM.SendAnyEmail("my@email.com", "String From PayPal ", strRequest);
    // I get the above email and life is good

    But when I add this bit, it breaks:

    // code breaks Here????
    //Send the request to PayPal and get the response
    StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
    streamOut.Write(strRequest);
    EM.SendAnyEmail("my@email.com", "String Back to PayPal ", strRequest);
    // I do NOT receive this email and life is not good
    streamOut.Close();
    
    StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
    string strResponse = streamIn.ReadToEnd();
    streamIn.Close();
    EM.SendAnyEmail("my@email.com", "String Response From PayPal ", strResponse);

    So something is breaking at:

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

    But for the life of me I can't see what the issue is and The "Simulator" tells me that "We could not send an IPN due to an HTTP Error" But it does not give me an error code.

    Here are the Error Messages off of the server.

    Could not establish trust relationship for the SSL/TLS secure channel. at System.Net.HttpWebRequest.GetRequestStream

    TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream()

    The remote certificate is invalid according to the validation procedure. at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)

    I thank you in advance for any help.

    Cheers, GW

    Wednesday, April 22, 2015 12:33 PM

All replies

  • User-540380721 posted
    Weedy please tell me you got to the bottom of this? After weeks of issues I have narrowed it down to the exact same problem as you have detailed.

    Please put me out of my misery!!

    Any help would be much appreciated!
    Tuesday, November 24, 2015 10:02 PM
  • User95943963 posted

    webinteraction -

    Yes, if I remember correctly it turned out that PayPal had updated it's encryption service at the server level and I had to update my server to accommodate. At the time I was running Windows Server 2003 & IIS6. And again if I remember correctly there was a means to update it with some quick fixes. But just a few months later I moved to a new server running Windows Server 2012 and it is not an issue as it accommodates the encryption as a default.

    Hope that helps

    Cheers,

    weedy

    Wednesday, November 25, 2015 1:34 PM