Paypal Sandbox IPN not detecting Content-type

此生再无相见时 提交于 2019-12-13 05:16:55

问题


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();
        ...

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/19105718/paypal-sandbox-ipn-not-detecting-content-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!