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数组内多维对象

    jquery数组内多维对象 var postData=[],obj,list; obj = !!obj ? obj : $('#dist_meici_checkinfo_form'); obj.fin ...

  2. mysql中,主键与普通索引

    一.什么是索引?索引用来快速地寻找那些具有特定值的记录,所有MySQL索引都以B-树的形式保存.如果没有索引,执行查询时MySQL必须从第一个记录开始扫描整个表的所有记录,直至找到符合要求的记录.表里 ...

  3. ajax调用aspx.cs中的WebMethod

    前台: <script language="javascript" src="../js/jquery-1.8.2.js"></script& ...

  4. 用pywinauto进行win32应用程序的测试

    之前做win32应用测试时,用过很多大家耳熟成详的工具,接触pywinauto之前,对它的了解也不多,然而,随着对它了解的增多,发现它借助了python动态对象的能力,使得代码即便于书定,也便于阅读, ...

  5. mysql查询当前正在使用数据库

    1.select database(): 2.status: 3.show tables:

  6. [转]Android中Application类的用法

    原文链接:http://www.cnblogs.com/renqingping/archive/2012/10/24/Application.html Application类 Application ...

  7. 数据结构顺序表删除所有特定元素x

    顺序表类定义: template<class T> class SeqList : { public: SeqList(int mSize); ~SeqList() { delete[] ...

  8. AIX系统中安装Java6全过程(全部)

    ====================================================   From: GCG TSC pSeries <ibm800p@cn.ibm.com& ...

  9. 【leetcode】Swap Nodes in Pairs (middle)

    Given a linked list, swap every two adjacent nodes and return its head. For example,Given 1->2-&g ...

  10. 【leetcode】Compare Version Numbers(middle)

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...