服务器端如何处理HTTP请求

发布于 2024-10-29 21:41:46 字数 354 浏览 2 评论 0原文

我们有一个 Rails 站点,它还连接到我们的供应商以从他们那里获取 XML 信息。为此,我使用 Net::HTTP 从我们这边发出请求,并将其视为“黑匣子”。

现在,我们的一位供应商希望以随机时间间隔向我们发送 XML 数据。即,它们发出 HTTP 请求,而不仅仅是响应我们的 HTTP 请求之一。

既然桌子已经摆在我们面前,我是否需要在我们的服务器上设置一些“特殊”的东西来监听他们的请求?

从逻辑上讲,他们的 HTTP 请求与浏览器发出的任何请求没有什么不同,在这种情况下,我需要做的就是告诉他们将其指向哪个“控制器/方法”。

我的问题是,真的那么简单吗?还是我必须设置其他东西?

We have an Rails site which also connects to our suppliers to get XML info from them. For that I use Net::HTTP to make requests from our end and think of it as 'black box' stuff.

Now one of our suppliers wants to send XML data to us at random intervals. i.e. They are the ones making the HTTP Request rather than just responding to one of our HTTP Requests.

Now that the table has been turned on us, do I need to set up something 'special' on our server to listen out for their requests?

Logic says that their HTTP Request is no different to any that a browser makes, in which case all I would need to do is tell them which 'Controller/Method' to point it at.

My question is, is it really that simple or do I have to set up other stuff?

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

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

发布评论

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

评论(2

听闻余生 2024-11-05 21:41:46

从最基本的角度来说,就是这么简单。处理 HTTP POST 或 PUT 请求的控制器方法将完成此操作。不过,复杂性可能会出现在其他领域:您需要决定是否要采取措施来确保数据仅来自您期望的位置,以及如果数据缺少关键字段(您通常会捕获这些字段)该怎么办进行验证并发送回用户)。

At its most basic, its that simple. A controller method that handles an HTTP POST or PUT request will do it. Complexity may show up in other areas though: You will need to decide if you want to do something to ensure that the data is only coming from where you expect, and what to do if their data is lacking key fields (which you would normally catch with validation and send back to the user).

情定在深秋 2024-11-05 21:41:46

我认为这没什么大不了的。您可以让您的 URL(控制器/操作)通过从请求中获取 xml 来服务请求并返回一些标志(文本)。您必须向供应商提供该 URL,并要求他在该 URL 上发布 xml。

I think its not a big deal. You can have your URL (controller/action) which serve the request by taking xml from the request and return some flag(text). You have to provide that URL to the suppliers and ask him to post xml on the same.

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