c# - Paypal 验证失败,无效

标签 c# paypal paypal-ipn

我正在尝试设置 PayPal Ipn,但它在某些订单验证上失败了。我发现如果用户名有一些非标准字母,如 &last_name=Montalvo Agüera,它会失败 我需要更改编码吗?

var request = "cmd=_notify-validate&.......";

const string strLive = "https://www.paypal.com/cgi-bin/webscr";
  var req = (HttpWebRequest)WebRequest.Create(strLive);
            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";

            req.ContentLength = request.Length;

            var streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
            streamOut.Write(request);
            streamOut.Close();
            var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            var strResponse = streamIn.ReadToEnd();
            streamIn.Close();

            Response.Write(strResponse);

最佳答案

你可以这样试试:

string strLive = "https://www.paypal.com/cgi-bin/webscr";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);

        //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#"));
        //req.Proxy = proxy;

        //Send the request to PayPal and get the response
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);

如果还是不行尝试把编码改成UTF8

关于c# - Paypal 验证失败,无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8709881/

相关文章:

c# - StackExchange.Redis 和 ServiceStack.Redis 的区别

c# - 我应该在何时/何处在我的 ASP.NET MVC 项目中创建以下类?

paypal - 使用 Paypal SandBox 测试支付

c# - IDictionary<K, IEnumerable/IList/ICollection<V>> 上的单一扩展方法

c# - 保护内存中的 REST token

android - REACT NATIVE 的 PayPal 支付集成与最新的 lib android + ios

Paypal (Payflow Pro) 错误 52

c# - PayPal IPN 集成(快速结账 - Razor/C#)

cakephp Paypal IPN 集成

php - Paypal 自适应/链式支付工作流程