Eli*_*ght 2 apache executable cgi-bin query-parameters
我的印象是,可以将任何旧的可执行程序放在cgi-binApache目录中,并将其用作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);
}
}
Run Code Online (Sandbox Code Playgroud)
然后转到,http://example.com/cgi-bin/TestProg?hello=kitty&goodbye=world然后将查询字符串hello=kitty&goodbye=world作为第一个参数传递给main,因此我的页面应如下所示
Arguments:
hello=kitty&goodbye=world
Run Code Online (Sandbox Code Playgroud)
不幸的是,我的查询参数都没有传递。页面加载并且仅打印而后Arguments:没有任何内容。
那么如何将查询参数传递给该程序?
参数不会在命令行上传递-相反,apache会在调用cgi程序之前设置环境变量(http://httpd.apache.org/docs/2.0/howto/cgi.html#behindscenes)。
您可以访问环境变量“ QUERY_STRING”,其中包含查询字符串的文本。
String queryString = System.Environment.GetEnvironmentVariable("QUERY_STRING");
Run Code Online (Sandbox Code Playgroud)
然后,您需要自己解析queryString。
但是,POST数据是通过STDIN传递的,因此您将需要使用Console.In进行处理。
| 归档时间: |
|
| 查看次数: |
4635 次 |
| 最近记录: |