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

示例

相关推荐
小小龙学IT6 天前
Apache Airflow 2.x 深度指南:用 Python 编排一切的现代化工作流引擎
开发语言·python·apache
Shepherd06196 天前
【IT 运维】Apache 使用 mod_remoteip 恢复 Cloudflare 后的真实访客 IP
运维·tcp/ip·apache
isyangli_blog6 天前
SDN 基本应用实践 —— 使用命令行实现简易防火墙功能实验报告
服务器·php·apache
小小龙学IT7 天前
Apache Pulsar 深度解析:从架构设计到生产落地
apache
Full Stack Developme8 天前
Apache Tika 教程
java·开发语言·python·apache
laplaya8 天前
C++大型项目组件通信与依赖管理实践
c++·log4j·apache
万岳科技8 天前
教育培训小程序如何构建线上线下一体化教学体系
小程序·apache
yyuuuzz9 天前
云服务器软件部署的几个常见问题
运维·服务器·开发语言·网络·云计算·php·apache
分布式存储与RustFS9 天前
Apache Iceberg数据湖轻量化搭建:基于Rust开源存储方案
开源·apache·iceberg·rustfs·ai存储·ai memory·s3 table
睡不醒男孩0308239 天前
中启乘数 CLup 6.x Apache Doris 存算一体集群管理技术文档
apache·doris·clup