Rails 上的 Pubsubhubbub。如何从 POST 请求中提取原始 POST 正文内容?

发布于 2024-08-24 10:18:22 字数 925 浏览 9 评论 0原文

我在使用 Rails 设置启用 pubsub 的订阅者应用程序时遇到问题。我目前已订阅开放集线器 pubsubhubbub.appspot.com,并且正在接收对我的应用程序端点的 ping。 (到目前为止,我已经创建了一个计数器,每次对端点进行 ping 操作时该计数器都会增加)。但我无法理解如何从 POST 中提取原始 POST 正文内容。我是 pubsub 的新手,很想尝试一下。我看到这篇博文,但它不是特定于语言的。


资料来源:Joseph Smarr:实施 PubSubHubbub 订户支持:分步指南。 http://josephsmarr。 com/2010/03/01/implementing-pubsubhubbub-subscriber-support-a-step-by-step-guide/

现在您已准备好 支付——神奇地接收来自 每次您访问博客时都会收到以太币 订阅了有新内容!你会 接收对您的入站请求 指定回调 URL,不带任何内容 添加了额外的查询参数 (即你会知道这是一个 ping 而不是 验证,因为不会有 包括任何 hub.mode 参数)。 相反,新条目 订阅的提要将被包括在内 直接在 POST 正文中 请求,带有请求内容类型 ATOM 提要的 application/atom+xml 以及用于 RSS 的 application/rss+xml 饲料。取决于您的编程 选择的语言,您需要 弄清楚如何提取原始 POST 正文内容。例如,在 PHP 中 你会打开特殊的文件名 php://输入来读取它。

任何帮助将不胜感激。

I am having trouble setting up a pubsub enabled subscriber app using rails. I have currently subscribed to the open hub pubsubhubbub.appspot.com and am receiving pings to my application's endpoint. (as of now i have created a counter which increments everytime the end point is pinged). But i am not able to understand as to how to extract the raw POST body contents from the POST. I am new to pubsub and am eager to experiment with it. I came across this blog post but it is not language specific.


Source: Joseph Smarr: Implementing PubSubHubbub subscriber support: A step-by-step guide. http://josephsmarr.com/2010/03/01/implementing-pubsubhubbub-subscriber-support-a-step-by-step-guide/

Now you’re ready for the
pay-out–magically receiving pings from
the ether every time the blog you’ve
subscribed to has new content! You’ll
receive inbound requests to your
specified callback URL without any
additional query parameters added
(i.e. you’ll know it’s a ping and not
a verification because there won’t be
any hub.mode parameter included).
Instead, the new entries of the
subscribed feed will be included
directly in the POST body of the
request, with a request Content-Type
of application/atom+xml for ATOM feeds
and application/rss+xml for RSS
feeds. Depending on your programming
language of choice, you’ll need to
figure out how to extract the raw POST
body contents. For instance, in PHP
you would fopen the special filename
php://input to read it.

Any help would be greatly appreciated.

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

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

发布评论

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

评论(1

泡沫很甜 2024-08-31 10:18:22

你没有说,但我假设你正在运行 Rails 3.x?

要获取原始 POST 正文,您只需在控制器中使用 request.raw_post 即可。这将为您提供一个看起来像请求参数字符串的长字符串:some_var=something&something_else=something_else... 然后您可以解析它以获得您想要的内容。

但是,请查看传入请求的开发日志,看看 params 哈希是否不是您更好的选择。该服务应将数据发布到某个变量名称下,例如上面的 some_var,并且 params 哈希将保存仅包含该数据的 params[:some_var]。换句话说,不需要你自己去挖掘它。

You didn't say but I'm assuming you are running Rails 3.x?

To get the raw POST body you simply use request.raw_post in your controller. This will give you a long string that looks like a request parameters string: some_var=something&something_else=something_else... which you can then parse to get at what you want.

However, look at you development logs for an incoming request and see if the params hash isn't a better option for you. The service should post the data under some variable name, such as some_var above, and the params hash will hold an params[:some_var] containing only that data. No need for you to dig it out on your own in other words.

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