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 天前
【数据分析/可视化】Apache Superset企业级BI数据可视化平台实战详解
信息可视化·数据分析·apache
万岳科技系统开发2 天前
互联网医院小程序搭建如何快速上线?完整建设方案解析
小程序·apache
南山丶无梅落4 天前
文件上传漏洞1
apache·绕过·文件上传漏洞·网安·upload闯关·文件类型验证
kke_884 天前
电商/教育/工具类小程序,UV分析的3种不同思路
大数据·apache
nvd115 天前
深度解析:Apache Beam YAML 部署至 GCP Dataflow 的架构与最佳实践
架构·apache
27669582926 天前
拼多多m端/小程序 encrypt_info
java·小程序·apache·encrypt_info·encrypt_info解密·拼多多小程序·拼多多m端
ylscode6 天前
Apache CXF LDAP注入漏洞允许攻击者获取任意证书
apache
MageGojo9 天前
小程序每日一谜怎么做:riddle 接口接入示例
windows·小程序·apache·谜语
penngo10 天前
FlowLoom:基于 Apache Spark 的可视化数据处理平台
大数据·spark·apache
Apache RocketMQ11 天前
全新 AI 消息模型:Apache RocketMQ 如何让 AI 应用拥抱事件驱动架构?
人工智能·apache·rocketmq