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

示例

相关推荐
麦兜*2 小时前
Spring Boot 整合 Apache Doris:实现海量数据实时OLAP分析实战
大数据·spring boot·后端·spring·apache
云边有个稻草人3 小时前
大数据时代下的时序数据库选型指南:为何Apache IoTDB成为最优解
大数据·apache·时序数据库·apache iotdb
JosieBook1 天前
【数据库】时序数据智能基座:Apache IoTDB 选型与深度实践指南
数据库·apache·iotdb
微学AI1 天前
时序数据库选型操作:Apache IoTDB 的深度实战应用
apache·时序数据库·iotdb
それども1 天前
Apache POI XSSFWorkbook 写入Excel文件的潜在风险
apache·excel
Benny的老巢2 天前
Mac上用XAMPP搭建局域网可访问的开发环境,让局域网内其他设备通过域名访问
nginx·macos·apache·xampp·php开发环境
Maggie_ssss_supp2 天前
Linux-Web服务(Apache)
linux·运维·apache
予枫的编程笔记2 天前
深度解析Apache RocketMQ:从核心原理到实战应用
java·apache·rocketmq
hopsky3 天前
2025 年 Apache DolphinScheduler 案例精选
apache
oMcLin4 天前
如何在 CentOS 7 上通过调优 Apache Tomcat 配置,提高高并发电商网站的性能?
centos·tomcat·apache