我一直在使用过去几个小时试图找出为什么Paypal Sandbox IPN模拟器没有在我的请求中检测到内容类型。我没有修改任何返回请求的代码,所以奇怪的是它没有正确完成。
三月份有一个similar question回来了,虽然他标记的答案对我来说似乎没有诀窍。
有没有人知道为什么会这样?这最近发生在其他人身上了吗?
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();
...
答案 0 :(得分:0)
因此,使用ASHX不起作用,但显然当我切换到ASPX文件时,它神奇地起作用。我不确定ASHX有什么不能使它工作,但ASPX是解决方案。
答案 1 :(得分:0)
我遇到了在Play2(Scala)中实现IPN侦听器的相同问题。
请注意。回复Paypal的请求的内容类型不是它所抱怨的,它是您回复原始Paypal IPN请求的响应,它会对您的监听服务产生影响。
我正在返回一个play.api.mvc.SimpleResult.Ok()(映射到Http 200)但是收到了“IPN未检测到内容类型”消息。
在我挠头并向自己证明我立即返回200之后,我重新阅读了文档并注意到“你的听众返回空 HTTP 200响应。”
所以相反我尝试了play.api.mvc.SimpleResult.Ok(“”)而且嘿presto它工作了!
所以看来你必须发送一些含有200响应的内容(一个空字符串)才能让测试服务满意。