如何按原始顺序获取 POST 参数(使用 Rails)?

发布于 2024-10-09 12:30:28 字数 330 浏览 6 评论 0原文

嘿!我正在集成 Paypal 的 IPN 系统,他们的身份验证过程要求我的服务器通过 POST 到 Paypal 来响应 Paypal 请求,其参数与 Paypal 发送给我的参数完全相同(尽管带有附加字符串)。因此,我将 params 哈希转换为字符串(适当格式化)并将其发送回,但看起来生成的字符串与原始 POST 参数的顺序不同(导致无法进行身份验证)。

有人知道我如何访问实际的 POST 参数本身(而不是参数哈希),以便我可以复制它并将其发送回 Paypal?问题是我发送到 Paypal 的参数顺序需要与到达我的服务器的请求完全相同。

这有道理吗?有什么想法吗?提前致谢!

——贾里德

Hey there! I'm integrating Paypal's IPN system, and their authentication process requires my server to respond to a Paypal request with a POST to Paypal with parameters EXACTLY the same as Paypal sent me (although with an appended string). So, I've turned the params hash into a string (appropriately formatted) and sent it back, but it looks like the resulting string is not in the same order as the original POST parameters (resulting in no authentication).

Anyone know how I can access the actual POST parameters themselves (as opposed to the params hash), so that I can copy that and send it back to Paypal? The catch is that the order of parameters that I send to Paypal needs to be exactly the same as the request that hit my server.

Does that make sense? Any thoughts? Thanks in advance!

--Jared

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纸短情长 2024-10-16 12:30:28

如果我没记错的话,Paypal 的 IPN 可能有点挑剔(您确实必须准确地向他们提供他们发送的内容并附加您的消息,否则什么都不起作用)。

您可能应该在控制器中获取原始发布数据,向其附加一个字符串,并在将其发回之前使用原始发布数据构建某种 HTTP 请求。我记得上次使用paypal的IPN时就这么做过,效果还算不错。

我会使用 ActionController#raw_post 并在发回请求之前修改它到贝宝。另请记住,IPN 响应有超时时间(我认为),如果 Paypal 没有返回预期的结果,他们可能会向您发送包含完全相同数据的多个通知,因此您可能需要在之前立即向他们发送请求你的代码还可以做其他事情。

Paypal's IPN can be a little finicky if I remember correctly (You really have to give them exactly what they sent with your message appended or nothing works).

You should probably grab the raw post data in your controller, append a string to it, and construct some sort of HTTP request with your raw post data before posting it back. I remember doing it the last time I used paypal's IPN, and it worked relatively well.

I would use ActionController#raw_post and just modify it before sending a request back to paypal. Also keep in mind there is a timeout for IPN responses (I think) and paypal may send you multiple notifications with the exact same data if they don't get back what they expect, so you probably want to send them a request back immediately before your code does anything else.

赠佳期 2024-10-16 12:30:28

您不能使用 params 哈希,顺序会丢失。使用原始请求字符串,例如 request.request_urirequest.query_string

You cannot use the params hash, ordering is lost. Use the original request strings, for example request.request_uri or request.query_string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文