step1下载:

ftp://ftp.gnu.org/gnu/cgicc/

step2:

tar xzf cgicc-X.X.X.tar.gz(用最新版本)

cd cgicc-X.X.X

./configure --prefix=/usr

/var/www/html/testcgi.html:

<html>
<head><title>Test CGIcc form</title></head>
<body bgcolor="#cccccc" text="#000000">
<h2>Test CGIcc form</h2>
<p>
<form method="post" action="/cgi-bin/testcgi">
Value  :
<input type="text" name="value1">
<p>
Value  :
<select name="value2">
   <option value=
   <option value=
   <option value=
</select>
<P>
Value  :
<input type="radio" name="value3" value="button1" checked="checked">Button1
<input type="radio" name="value3" value="button2">Button2

<input type="hidden" name="value4" value="data4">
<p>
<input type="submit" value="Submit">
</form>
</body>
</html>

/var/www/cgi-bin/testcgi.cpp

#include <iostream>
#include <vector>
#include <string>

#include "cgicc/CgiDefs.h"
#include "cgicc/Cgicc.h"
#include "cgicc/HTTPHTMLHeader.h"
#include "cgicc/HTMLClasses.h"

#include <stdio.h>
#include <stdlib.h>

using namespace std;
using namespace cgicc;     // Or reference as cgicc::Cgicc formData; below in object instantiation.

int main(int argc, char **argv)
{
    try {
       Cgicc formData;

       // Send HTTP header: Content-type: text/html
       cout << HTTPHTMLHeader() << endl;

       // Print: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
       cout << HTMLDoctype(HTMLDoctype::eStrict) << endl;

       // Print: <html lang="en" dir="LTR">
       cout << html().set("lang", "EN").set("dir", "LTR") << endl;

       // Set up the HTML document
       cout << html() << head() << title("Cgicc example") << head() << endl;
       cout << body().set("bgcolor","#cccccc").set("text","#000000").set("link","#0000ff").set("vlink","#000080") << endl;

       cout << h1("This is a demonstration of the GNU CgiCC library") << endl;

       form_iterator fvalue1 = formData.getElement("value1");
       if( !fvalue1->isEmpty() && fvalue1 != (*formData).end()) {
          cout << "Value1: " << **fvalue1 << endl;
       }
       else
          cout << "No text entered for value1" << endl;

       cout << p();

       form_iterator fvalue2 = formData.getElement("value2");
       if( !fvalue2->isEmpty() && fvalue2 != (*formData).end()) {
          // Note this is just a different way to access the string class.
          // See the YoLinux GNU string class tutorial.
          cout << "Value2: " << (**fvalue2).c_str() << endl;
       }

       cout << p();

       form_iterator fvalue3 = formData.getElement("value3");
       if( !fvalue3->isEmpty() && fvalue3 != (*formData).end()) {
          cout << "Value3: " << **fvalue3 << endl;
       }

       cout << p();

       form_iterator fvalue4 = formData.getElement("value4");
       if( !fvalue4->isEmpty() && fvalue4 != (*formData).end()) {
          cout << "Value4: " << **fvalue4 << endl;
       }

       // Close the HTML document
       cout << body() << html();
    }
    catch(exception& e) {
       // handle any errors here.
       cout << "ERROR!!" << endl;
    }
    ;   // To avoid Apache errors.
}

testcgi testcgi.cpp -lcgicc

访问:

参考:

http://www.yolinux.com/TUTORIALS/LinuxTutorialC++CGI.html

备注:

我虚拟机环境需要开通防火墙:

iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

The following paths are for a Red Hat 7.x installation.

  1. Place web page in: /var/www/html/testcgi.html
  2. Place cgi in: /var/www/cgi-bin/testcgi
  3. Start Apache: service httpd start
  4. Test: http://localhost/testcgi.html

Linux环境下使用C/C++编写CGI(httpd)的更多相关文章

  1. Linux环境下C语言线程创建---简单代码

    在Linux环境下用C语言编写线程创建. //file name: pthreadtext.c #include <stdio.h> #include <pthread.h> ...

  2. PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)

    源码地址:https://github.com/Tinywan/PHP_Experience 测试环境配置: 环境:Windows 7系统 .PHP7.0.Apache服务器 PHP框架:ThinkP ...

  3. 教你如何在Kali Linux 环境下设置蜜罐?

    导读 Pentbox是一个包含了许多可以使渗透测试工作变得简单流程化的工具的安全套件.它是用Ruby编写并且面向GNU/Linux,同时也支持Windows.MacOS和其它任何安装有Ruby的系统. ...

  4. linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)

     linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...

  5. 多线程编程之Linux环境下的多线程(一)

    一.Linux环境下的线程 相对于其他操作系统,Linux系统内核只提供了轻量级进程的支持,并未实现线程模型.Linux是一种“多进程单线程”的操作系统,Linux本身只有进程的概念,而其所谓的“线程 ...

  6. LINUX环境下SVN安装与配置(利用钩子同步开发环境与测试环境)

    安装采用YUM一键安装: 1.环境Centos 6.6 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /www/svndata svnserve ...

  7. 嵌入式LINUX环境下视频采集知识

    V4L2是Linux环境下开发视频采集设备驱动程序的一套规范(API),它为驱动程序的编写提供统一的接口,并将所有的视频采集设备的驱动程序都纳入其的管理之中.V4L2不仅给驱动程序编写者带来极大的方便 ...

  8. 【Jmeter自学】Linux环境下Jmeter运行

    ==================================================================================================== ...

  9. 【原创】Linux环境下的图形系统和AMD R600显卡编程(1)——Linux环境下的图形系统简介

    Linux/Unix环境下最早的图形系统是Xorg图形系统,Xorg图形系统通过扩展的方式以适应显卡和桌面图形发展的需要,然而随着软硬件的发展,特别是嵌入式系统的发展,Xorg显得庞大而落后.开源社区 ...

随机推荐

  1. jQuery调用后台方法

    前台: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.as ...

  2. Linux基础命令总结

    1.pwd  查看当前工作目录 2.ls [目录] 列出指定目录下的所有文件,使用 ls -l 或者 ll 列出文件详细列表包括权限.大小等文件默认大小以字节B为单位,目录大小为4096B  ls - ...

  3. 如何为自己的windows 8系统的电脑更换锁屏壁纸

    现在的人都喜欢个性,今天教大家如何设置自己想要的锁屏壁纸 工具/原料 Windows 8系统的笔记本电脑 方法/步骤   将鼠标移到电脑的右下方,点击设置按钮进入设置页面   找到更改电脑设置并点击进 ...

  4. Selenium webdriver 操作日历控件

    一般的日期控件都是input标签下弹出来的,如果使用webdriver 去设置日期, 1. 定位到该input 2. 使用sendKeys 方法 比如: 但是,有的日期控件是readonly的 比如1 ...

  5. Java数组的复制Arrays.copyOf()、System.arraycopy()、nums.clone()

    public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length); a ...

  6. AIX系统的环境变量设置

    AIX系统的环境变量设置 用户环境的定义是通过设置环境变量来实现的.AIX系统主要使用两大类profile文件来定义用户环境.一类是用来为所有用户定制环境,另一类是为个人定义自己的环境. 登录时,sh ...

  7. 【leetcode】Substring with Concatenation of All Words (hard) ★

    You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...

  8. Java容器题库

    一.    填空题 Java集合框架提供了一套性能优良.使用方便的接口和类,包括Collection和Map两大类,它们都位于  java.util  包中 队列和堆栈有些相似,不同之处在于栈是先进后 ...

  9. Redis事件管理(三)

    Redis的事件管理和定时器的管理都是自己来实现的,Redis的事件管理分为两部分,一部分是封装了系统的异步事件API,还有一部分是在这基础上封装了一个通用的事件管理器,根据具体的系统来决定具体使用哪 ...

  10. UVa815_Flooded!

    #include <iostream> //#include <fstream> #include <iomanip> #include <cstdio> ...