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

示例

相关推荐
是Dream呀14 小时前
时序数据库选型指南:Apache IoTDB企业级解决方案深度解析
apache·时序数据库·iotdb
一个天蝎座 白勺 程序猿14 小时前
Apache IoTDB(5):深度解析时序数据库 IoTDB 在 AINode 模式单机和集群的部署与实践
数据库·apache·时序数据库·iotdb·ainode
智_永无止境1 天前
Apache Commons Math3 使用指南:强大的Java数学库
apache·math
一只 Lemon2 天前
jquery 文件上传 (CVE-2018-9207)漏洞复现
apache
喜欢你,还有大家3 天前
Apache服务——搭建实验
apache
一休哥助手3 天前
Apache Thrift:跨语言服务开发的高性能RPC框架指南
网络协议·rpc·apache
Apache IoTDB3 天前
Apache IoTDB V1.3.5 发布|优化加密算法,优化内核稳定性,修复社区反馈问题
apache·iotdb
悠悠~飘3 天前
php学习(第四天)
php·apache
白鹭3 天前
apache实现LAMP+apache(URL重定向)
linux·运维·apache·url重定向·apache实现lamp架构
aramae3 天前
终端之外:解锁Linux命令行的魔法与力量
linux·服务器·apache