Apache中使用CGI

Apache24

使用Visual Studio 2022

cpp 复制代码
// 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 复制代码
<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了可以忽略

启动

如图

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

cpp 复制代码
#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);
}

示例

相关推荐
是馄饨呀14 小时前
Apache Tomcat RewriteValve路径遍历漏洞(CVE-2025-55752)修复
java·tomcat·apache
D愿你归来仍是少年16 小时前
Apache Spark Real-Time Mode 深度解析:打破微批次壁垒,挑战 Flink 的实时王座
flink·spark·apache
zhglhy16 小时前
Apache SkyWalking分布式链路实现
分布式·apache·skywalking
我不听你讲话1 天前
LNMP网络服务搭建
linux·php·apache
吴声子夜歌1 天前
小程序——开发接口(授权)
小程序·apache
、花无将2 天前
安装:apache-tomcat
java·tomcat·apache
微学AI2 天前
时序数据库选型:聚焦时间序列数据库Apache IoTDB——为工业物联网与大数据而生
数据库·apache·时序数据库
小邓睡不饱耶3 天前
Apache Flume 1.12.0 深度实战:从架构内核到企业级高可用部署(附完整代码案例)
架构·apache·flume
家有娇妻张兔兔3 天前
Apache Doris 副本故障排查与修复实战指南
apache·doris·时序库
一个天蝎座 白勺 程序猿4 天前
Apache IoTDB(18):IoTDB时序数据库的数据同步之Pipe机制与插件同步指南
数据库·apache·时序数据库·iotdb