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);
}

示例

相关推荐
分布式存储与RustFS1 小时前
RustFS永久开源承诺深度解读:Apache 2.0协议、商业化边界、社区可信度
开源·apache·数据安全·对象存储·minio·企业存储·rustfs
D愿你归来仍是少年20 小时前
Apache Spark 第 9 章:Spark 性能调优
大数据·spark·apache
Hello.Reader1 天前
Apache Arrow 在 PySpark 中的使用提速 Pandas 转换与 UDF 的关键武器
apache·pandas
言之。1 天前
Apache ZooKeeper 核心技术全解(面试+实战版)
zookeeper·面试·apache
AI架构师之家2 天前
Apache Camel使用教程一
apache
yzx9910132 天前
实时数据处理实战:使用 Apache Flink 消费 Kafka 数据并进行窗口聚合
flink·kafka·apache
Shepherd06193 天前
【IT 实战】Apache 反向代理 UniFi Controller 的终极指北(解决白屏、502、400 错误)
运维·网络·apache·it·unifi
额1293 天前
CentOS 7 安装apache部署discuz导入数据库表
数据库·centos·apache
qzhqbb3 天前
Nginx/Apache 访问规则
运维·nginx·apache
HashData酷克数据4 天前
# Apache Cloudberry 2.1.0 版本前瞻:内核、PXF 与备份生态持续演进
apache