将 CGI 参数传递给 Windows 上 Apache 中的可执行文件
我的印象是,我可以将任何旧的可执行程序放入 Apache 的 cgi-bin 目录中,并将其用作 CGI 脚本。具体来说,如果我有一个 C# 程序
static class TestProg
{
static void Main(string[] args)
{
Console.Write("Content-type: text/plain\r\n\r\n");
Console.WriteLine("Arguments:");
foreach (string arg in args)
Console.WriteLine(arg);
}
}
,然后转到 http://example.com/cgi-bin/TestProg?hello=kitty&goodbye=world 然后查询字符串 hello=kitty& ;goodbye=world
将作为第一个参数传递给 main,所以我的页面应该看起来像
Arguments:
hello=kitty&goodbye=world
不幸的是,我的查询参数都没有被传递;页面加载并仅打印 Arguments:
,后面没有任何内容。
那么如何将查询参数传递给该程序呢?
I was under the impression that I could put any old executable program in the cgi-bin
directory of Apache and have it be used as a CGI script. Specifically, if I have a C# program
static class TestProg
{
static void Main(string[] args)
{
Console.Write("Content-type: text/plain\r\n\r\n");
Console.WriteLine("Arguments:");
foreach (string arg in args)
Console.WriteLine(arg);
}
}
and then go to http://example.com/cgi-bin/TestProg?hello=kitty&goodbye=world
then the query string hello=kitty&goodbye=world
would be passed as the first parameter to main, so my page should look like
Arguments:
hello=kitty&goodbye=world
Unfortunately, none of my query parameters are getting passed; the page loads and just prints Arguments:
with nothing following it.
So how do I get my query parameters passed to this program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
参数不会在命令行上传递 - 相反,apache 在调用 cgi 程序之前设置环境变量(http://httpd.apache.org/docs/2.0/howto/cgi.html#behindscenes)。
您可以访问包含查询字符串文本的环境变量“QUERY_STRING”。
然后您需要自己解析 queryString。
然而,POST 数据是通过 STDIN 传递的,因此您需要使用 Console.In 来处理它。
Arguments are not passed on the command line - instead, apache sets environment variables before the cgi program is called (http://httpd.apache.org/docs/2.0/howto/cgi.html#behindscenes).
You can access the environment variable 'QUERY_STRING' which contains the text of the query string.
You will then need to parse queryString yourself.
POST data, however, is passed over STDIN, so you will need to use Console.In to process it.
我已经很久没有使用 CGI 和 Apache 了,但是如果我没记错的话,查询字符串是 Apache 中的一个环境变量。在 C# 中,您可以使用 System.Environment.GetEnvironmentVariables 查看环境。我没有任何已发表的文档来支持我,但我会先尝试一下看看。
It has been a long time since I've worked with CGI and Apache, but if I recall correctly, the query string is an environment variable in Apache. In C#, you can see the environment with System.Environment.GetEnvironmentVariables. I don't have any published docs to back me up, but I'd try that out first and see.