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

示例

相关推荐
你才是臭弟弟1 天前
Apache Flink+Apache Iceberg(协作关系)
大数据·flink·apache
SelectDB技术团队2 天前
构建 AI 数据基座:思必驰基于 Apache Doris 的海量多模态数据集管理实践
人工智能·apache·知识图谱
你才是臭弟弟2 天前
Apache Iceberg+Apache Flink(安装流程)
大数据·flink·apache
你才是臭弟弟2 天前
Apache Iceberg核心特征
大数据·apache
沉默-_-3 天前
微信小程序页面配置详解
学习·微信小程序·apache·微信开发者工具
SeaTunnel3 天前
Apache SeaTunnel MySQL CDC 支持按时间启动吗?
大数据·数据库·mysql·开源·apache·seatunnel
weixin_462446234 天前
Java 使用 Apache Batik 将 SVG 转换为 PNG(指定宽高)
java·apache·svg转png
学习3人组4 天前
Apache Superset开源现代化数据BI工具
开源·apache
SelectDB技术团队4 天前
AI 能力揭秘(五):Apache Doris 原生向量检索的设计及实现
人工智能·apache
Apache IoTDB4 天前
Apache IoTDB V2.0.6/V1.3.6 发布|新增查询写回功能,优化查询与同步性能
apache·iotdb