欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

怎么在windowsxp上运行用c 编写cgi

更新时间: 2014-01-05 02:03:18 责任编辑: Author_N1

 

如何在windowsXP下运行用c 编写cgi

如何在windowsXP下运行用c 编写cgi?

       前提是安装apache服务器,apache服务器的conf里面在<IfModule mime_module>里面配置好。

AddType text/html .exe
AddHandler cgi-script .exe .cgi
然后只要把exe文件放到cgi-bin下面就好了
http://127.0.0.1/cgi-bin/1.exe
就可以访问了
cout/printf出来的会输出到网页上

 

添加效果如下图所示:


不过注意的是:第一行一定要输出一个空行。

示例如下:

//2012-12-4-------------------------------

//仅在VC6.0平台下测试可得好多环境变量都不存在!

//而在安装了Apache服务器后显示会有所不同。

int main ( int argc, char *argv[] )
{
    char *env_var[24] =
{
                     "COMSPEC",
                     "DOCUMENT_ROOT",
                     "GATEWAY_INTERFACE",
                     "HTTP_ACCEPT",
                     "HTTP_ACCEPT_ENCODING",
                     "HTTP_ACCEPT_LANGUAGE",
                     "HTTP_CONNECTION",
                     "HTTP_HOST",
                     "HTTP_USER_AGENT",
                     "PATH",
                     "QUERY_STRING",
                     "REMOTE_ADDR",
                     "REMOTE_PORT",
                     "REQUEST_METHOD",
                     "REQUEST_URI",
                     "SCRIPT_FILENAME",
                     "SCRIPT_NAME",
                     "SERVER_ADDR",
                     "SERVER_ADMIN",
                     "SERVER_NAME",
                     "SERVER_PORT",
                     "SERVER_PROTOCOL",
                     "SERVER_SIGNATURE",
                     "SERVER_SOFTWARE"
       };
      
    printf ("%s\n","Content-Type: text/html\n" );
    printf ( "%s\n","<?xmlversion = \"1.0\"?>" );
    printf ("%s\n","<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML1.1//EN\" " );
    printf ("%s\n","\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">");
    printf ( "%s\n","<htmlxmlns = \"http://www.w3.org/1999/xhtml\">" );
    printf ("%s\n","<head><title>CGI环境变量</title></head><body>" );
    printf ( "%s\n","<tableborder = \"0\" cellspacing = \"2\">" );
      
for( int i=0;i<24;i++ )
{
        printf ("%s%s%s\n","<tr><td>",env_var[i],"</td><td>");
        char *value = getenv( env_var[i]);
             
        if ( value )
              {
            printf ( "%s",value );
        }
        else
              {
            printf ( "%s","CGI环境变量不存在." );
        }
        printf ("%s\n","</td></tr>" );
    }
      
    printf ("%s\n","</table></body></html>" );
    printf ( "%s\n","C语言编写" );
    return EXIT_SUCCESS;
}


 

输出结果显示:

注意:以上结果是在安装了Apache服务器后的结果,如下图:

 

       示例及显示结果:

void main()
{
       printf("Contenttype:text/html\n\n");
       printf("<html>\n");
       printf("<head><title>anHTML Page From a CGI</title></h ead>\n");
       printf("<body><br>\n");
       printf("<h2>This is an HTML page generated from with in a CGI program...</h2>\n");
       printf("<hr><p>\n");
       printf("<ahref=\"../output.html#two\"><b> Go back to output.html page</b></a>\n");
       printf("</body>\n");
       printf("</html>\n");
       fflush(stdout);
}


       

上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 02:03:18
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/5076/
本文WWW.DOC100.NET DOC100.NET版权所有。