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

示例

相关推荐
超级小忍10 天前
Spring Boot 集成 Apache Kafka 实战指南
spring boot·kafka·apache
天上掉下来个程小白12 天前
Apache ECharts-02.入门案例
前端·spring boot·apache·echarts·苍穹外卖
SelectDB技术团队13 天前
Apache Doris 3.0.6 版本正式发布
大数据·数据分析·apache·实时分析·极速分析
guygg8813 天前
Linux中的阻塞信号与信号原理
linux·mysql·apache
天上掉下来个程小白14 天前
Apache ECharts-01.介绍
前端·javascript·spring boot·apache·苍穹外卖
gb421528715 天前
高性能场景使用Protocol Buffers/Apache Avro进行序列化怎么实现呢
apache
midsummer_woo15 天前
复现 apache HTTPD 换行解析漏洞(CVE-2017-15715)
web安全·apache
心灵宝贝15 天前
Apache JMeter 2.9使用教程:压力测试入门步骤详解
jmeter·apache·压力测试