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

示例

相关推荐
leikooo1 小时前
ShardingSphere 下更新分片键导致的失败问题分析与解决
java·spring·apache
一个天蝎座 白勺 程序猿4 小时前
Apache IoTDB(13):数据处理的双刃剑——FILL空值填充与LIMIT/SLIMIT分页查询实战指南
数据库·sql·ai·apache·时序数据库·iotdb
阿巴资源站4 小时前
小程序原生授权手机号
小程序·apache
亲爱的非洲野猪6 小时前
Apache Cassandra完全指南:架构、原理与生产实践深度解析
架构·apache·database·cassandra
Hello.Reader1 天前
Apache Cassandra Connector:Flink 与宽列存储的高吞吐协作
大数据·flink·apache
可涵不会debug2 天前
时序数据库选型指南:以Apache IoTDB为核心的大数据解决方案
apache·时序数据库·iotdb
安小牛2 天前
Apache License 2.0的中文介绍及其许可使用
笔记·apache
鸽芷咕2 天前
时序数据库选型指南:Apache IoTDB为何成大数据场景优选
apache·时序数据库·iotdb
ApachePulsar2 天前
演讲回顾|Apache Pulsar 在腾讯云上的高可用性最佳实践
云计算·apache·腾讯云
byte轻骑兵2 天前
时序数据库选型指南:以Apache IoTDB为例看国产时序数据库的优势与实践
大数据·数据分析·apache·时序数据库·iotdb