Question

I've been using the past few hours attempting to figure out why the Paypal Sandbox IPN Simulator isn't detecting a Content-type on my request back. I didn't modify any of the code where the request back is made, so it's odd that it's not going through correctly.

There was a similar question back in March, though the answer he marked didn't seem to do the trick for me.

Does anyone have any idea on why this is happening? Has this happened to anyone else recently?

public class PaypalIPN : IHttpHandler, IRequiresSessionState {

    public void ProcessRequest (HttpContext context)
    {
        //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 = context.Request.BinaryRead(HttpContext.Current.Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(param);
        strRequest += "&cmd=_notify-validate";
        req.ContentLength = strRequest.Length;

        //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();
        ...
Was it helpful?

Solution

So, using ASHX didn't work, but apparently when I switched over to a ASPX file, it magically worked. I'm not sure what ASHX has that doesn't make it work, but ASPX was the solution.

OTHER TIPS

I've just run into the same issue implementing an IPN Listener in Play2 (Scala).

Please note. It is not the content type of your request back to Paypal that its complaining about, its the response you are returning to the original Paypal IPN request that it makes to your listener service.

I was returning a play.api.mvc.SimpleResult.Ok() (that maps to Http 200) but was getting the "IPN not detecting Content-type" message.

After scratching my head and proving to myself that I was immediately returning 200 I re-read the documentation and noticed "Your listener returns an empty HTTP 200 response."

So instead I tried play.api.mvc.SimpleResult.Ok("") and hey presto it worked!

So it seems you must send some content (an empty string) with the 200 response for the test service to be happy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top