0

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?
4

2 回答 2

2

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

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

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

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

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

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

于 2009-10-09T15:34:26.673 回答
0

您可能正在寻找的概念称为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/获取页面。

于 2009-10-08T18:03:11.393 回答