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

示例

相关推荐
小当家.1052 小时前
《Java操作Excel实战教程:Apache POI从入门到精通》
java·apache·excel
Gobysec4 小时前
Goby 漏洞安全通告|Apache Struts XWork 组件 XML外部实体注入漏洞(CVE-2025-68493)
struts·安全·apache
坚持学习前端日记4 小时前
学校管理系统 ER图
java·运维·服务器·mysql·apache
zhojiew4 小时前
Kafka Connect集成Apache Iceberg写入AWS Glue表
kafka·apache·aws
lang201509281 天前
Java反射利器:Apache Commons BeanUtils详解
java·开发语言·apache
oMcLin1 天前
如何在 Debian 11 上通过构建大数据湖,使用 Apache Spark 加速电商平台的数据分析与实时推荐引擎
spark·debian·apache
Apache IoTDB1 天前
Apache IoTDB “入驻” Google Code Wiki 技术知识库!
apache·iotdb
xiaoliuliu123451 天前
apache-tomcat-6.0.10使用步骤详解(附启动与部署教程)
java·tomcat·apache
360智汇云2 天前
HULK PostgreSQL 图数据库化方案:Apache AGE 的引入与实践
数据库·postgresql·apache
SelectDB技术团队2 天前
驾驭 CPU 与编译器:Apache Doris 实现极致性能的底层逻辑
数据库·数据仓库·人工智能·sql·apache