您的位置:首页 > 房产 > 家装 > Apache中使用CGI

Apache中使用CGI

2024/10/7 2:20:45 来源:https://blog.csdn.net/lgq1368853532/article/details/140316098  浏览:    关键词:Apache中使用CGI

Apache24

使用Visual Studio 2022

// CGI2.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <stdio.h>
#include <stdlib.h>#include <stdio.h>void main()
{//设置HTML语言printf("Content-type:text/html\n\n");//打印hello world, 我来自CGI//html中的换行符为<br>printf("hello world, 我来自CGI !<br>");
}

这个目录下的exe文件粘贴到

Apache24\cgi-bin,改.cgi也可以

htdocs\index.html

添加如下代码,

<html><body><h1>It works!</h1></body></html>
<html>
<body><form method=get action="\cgi-bin\CGI2.exe"><!-- #config timefmt="%y年%m月%d日"--><p><!--#echo var="LAST_MODIFIED"--></p>i1:<input type="text" name="i1"/>i2:<input type="text", name="i2"/><input type="submit"/></form>
</body>
</html>

  <!-- #config timefmt="%y年%m月%d日"-->
        <p><!--#echo var="LAST_MODIFIED"--></p>

代码自己搞SSI了可以忽略

启动

如图

计算器加法程序,编译报错点重试

#include <stdio.h>
#include <stdlib.h>void main()
{//设置HTML语言printf("Content-type:text/html\n\n");int i1, i2;//定义2个变量用于接收传递的参数char* queryString = getenv("QUERY_STRING");sscanf(queryString, "i1=%d&i2=%d", &i1, &i2);printf("%d+%d=%d", i1, i2, i1 + i2);
}

示例

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com