Apache中使用CGI

Apache24

使用Visual Studio 2022

// 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><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了可以忽略

启动

如图

计算器加法程序,编译报错点重试

#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. web server apache tomcat11-14-CGI

    2024-07-11 22:00:02       31 阅读
  2. 12、Spring CLI的角色使用

    2024-07-11 22:00:02       35 阅读
  3. web server apache tomcat11-33-CDI

    2024-07-11 22:00:02       32 阅读
  4. docker安装的php 在cli使用

    2024-07-11 22:00:02       52 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 22:00:02       70 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 22:00:02       74 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 22:00:02       62 阅读
  4. Python语言-面向对象

    2024-07-11 22:00:02       72 阅读

热门阅读

  1. conda 重命名虚拟环境

    2024-07-11 22:00:02       22 阅读
  2. conda

    2024-07-11 22:00:02       20 阅读
  3. Facebook应用开发:认证与授权登录流程详解

    2024-07-11 22:00:02       23 阅读
  4. css中伪元素 :: before的用法

    2024-07-11 22:00:02       25 阅读
  5. 机器学习深度学习用得到的数据集

    2024-07-11 22:00:02       30 阅读
  6. 设计模式:单例模式

    2024-07-11 22:00:02       25 阅读