【问题标题】:PayPal verify fail with InvalidPayPal 验证失败并显示无效
【发布时间】:2012-02-01 08:26:41
【问题描述】:

我正在尝试设置 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);

【问题讨论】:

    标签: c# paypal paypal-ipn


    【解决方案1】:

    你可以这样试试:

    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

    【讨论】:

    • 我遇到了同样的问题。某些订单的状态无效。
    • 如果我将其更改为 UTF8,我会收到错误“在写入所有字节之前无法关闭流。”
    • 我认为你应该联系贝宝
    【解决方案2】:

    您需要对参数进行 url 编码。这就是req.ContentType = "application/x-www-form-urlencoded"; 的意思。是您向 HTTP 服务器(在本例中为 PayPal 的 www.paypal.com)做出承诺。承诺是您发送的任何数据都将进行 url 编码。这意味着您必须转义任何特殊字符。这包括 ?&% 等字符以及 ü 等字符。

    要对名称进行 url 编码,您需要使用 url 编码的名称构建请求:

    string request = "cmd=_notify-validate&......."; // don't include "last_name="
    string name = "Montalvo Agüera";
    request += "last_name=" + Server.UrlEncode(name);
    

    【讨论】:

    • 仍然无效。两天试图解决问题,但没有任何成功。我从“即时付款通知 (IPN) 详细信息”页面收到 IPN 消息,其中一些工作失败。我什至认为只需删除验证。
    • 您能否编辑问题,使其包含两个示例请求 - 一个有效,一个无效?可能还有其他问题。
    猜你喜欢
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-23
    • 2021-06-14
    • 2013-07-09
    • 2011-06-23
    相关资源
    最近更新 更多