使用CGI时可以转发请求吗?

发布于 2024-08-06 15:20:41 字数 230 浏览 3 评论 0原文

我正在编写一个小型内容服务器作为网络服务。有 2 个单元 - 一个对请求内容的应用程序进行身份验证,当身份验证成功时,请求将转发到提供内容的另一个单元。

  • [1] 如果我想使用 CGI 来做到这一点 脚本,有没有等价的 CGI 中的jsp:forward
  • [2] 假设如果 无法转发,则 客户端应用程序不应该能够 直接请求第二个单元。 执行此操作的正确方法是什么?

I'm writing a small content server as a web service. There are 2 units - one authenticates the application requesting content and when authentication succeeds, the request is forwarded to the other unit that serves the content.

  • [1] If I want to do this using CGI
    scripts, is there any equivalent of
    jsp:forward in CGI?
  • [2] Suppose if
    forwarding is not possible, the
    client application shouldn't be able
    to request the second unit directly.
    What is the proper way to do this?

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

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

发布评论

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

评论(2

筱果果 2024-08-13 15:20:41

另一种尝试,因为您不是在 HTTP 重定向之后...

简短的答案是:是的,这是可能的。

但是,它高度依赖于您使用的工具。您使用什么 Web 服务器和 CGI​​ 脚本语言?

CGI 脚本实际上可以执行它们想做的任何事情,例如它们可以执行其他 CGI 脚本中的代码。因此,他们可以提供您正在寻找的行为。

CGI(通用网关接口)只是描述了Web服务器如何启动CGI脚本并给出脚本通过环境变量输入数据。 CGI 还描述了脚本如何将数据返回到 Web 服务器。就这样。

因此,如果您的授权脚本想要将某些操作委托给其他脚本,则由该授权脚本以某种方式实现它。 CGI 协议在这里没有帮助。

Another attempt, since you are not after HTTP redirect...

The short answer is: Yes, it is possible.

However, it is highly dependent on the tools you are using. What web server and CGI scripting language you are using?

CGI scripts can do practically anything they want to do, for example they could execute code from other CGI scripts. Thus, they can provide the behavior you are looking for.

CGI (Common Gateway Interface) just describes how a web server starts a CGI script and gives the script input data via environment variables. CGI also describes how the script returns data to web server. That's all.

So if your authorization script wants to delegate some operation to other some script, it is up to that authorization script to implement it somehow. The CGI protocol does not help here.

舟遥客 2024-08-13 15:20:41

您可能正在寻找的概念称为 HTTP 重定向,其中服务器将响应发送到浏览器的请求,告诉浏览器从另一个 URL 获取新页面。

CGI 可以很好地执行 HTTP 重定向,就像 jsp:forward 一样。您只需要输出正确的 HTTP 标头即可。

您需要在 HTTP 标头中返回 302 响应代码,并提供浏览器下一步应访问的位置 URL。让您的 CGI 脚本输出这些类型的标头:

HTTP/1.1 302 Redirect
Location: http://www.example.org/

这些标头告诉浏览器从 URL http://www.example 获取页面.org/ .

The concept you might be looking for is called HTTP redirect, where the server sends a response to browser's request, telling the browser to fetch a new page from another URL.

CGI can do HTTP redirects just fine just like jsp:forward. You need just to output the right HTTP headers.

You need to return a 302 response code in HTTP headers, and provide location URL where browser should go next. Have your CGI script output these kind of headers:

HTTP/1.1 302 Redirect
Location: http://www.example.org/

These headers tell browser to fetch a page from URL http://www.example.org/ .

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