Linux环境下使用C/C++编写CGI(httpd)
step1下载:
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.
- Place web page in: /var/www/html/testcgi.html
- Place cgi in: /var/www/cgi-bin/testcgi
- Start Apache: service httpd start
- Test: http://localhost/testcgi.html
Linux环境下使用C/C++编写CGI(httpd)的更多相关文章
- Linux环境下C语言线程创建---简单代码
在Linux环境下用C语言编写线程创建. //file name: pthreadtext.c #include <stdio.h> #include <pthread.h> ...
- PHP 命令行模式实战之cli+mysql 模拟队列批量发送邮件(在Linux环境下PHP 异步执行脚本发送事件通知消息实际案例)
源码地址:https://github.com/Tinywan/PHP_Experience 测试环境配置: 环境:Windows 7系统 .PHP7.0.Apache服务器 PHP框架:ThinkP ...
- 教你如何在Kali Linux 环境下设置蜜罐?
导读 Pentbox是一个包含了许多可以使渗透测试工作变得简单流程化的工具的安全套件.它是用Ruby编写并且面向GNU/Linux,同时也支持Windows.MacOS和其它任何安装有Ruby的系统. ...
- linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg)
linux环境下安装sphinx中文支持分词搜索(coreseek+mmseg) 2013-11-10 16:51:14 分类: 系统运维 为什么要写这篇文章? 答:通过常规的三大步(./confi ...
- 多线程编程之Linux环境下的多线程(一)
一.Linux环境下的线程 相对于其他操作系统,Linux系统内核只提供了轻量级进程的支持,并未实现线程模型.Linux是一种“多进程单线程”的操作系统,Linux本身只有进程的概念,而其所谓的“线程 ...
- LINUX环境下SVN安装与配置(利用钩子同步开发环境与测试环境)
安装采用YUM一键安装: 1.环境Centos 6.6 2.安装svnyum -y install subversion 3.配置 建立版本库目录mkdir /www/svndata svnserve ...
- 嵌入式LINUX环境下视频采集知识
V4L2是Linux环境下开发视频采集设备驱动程序的一套规范(API),它为驱动程序的编写提供统一的接口,并将所有的视频采集设备的驱动程序都纳入其的管理之中.V4L2不仅给驱动程序编写者带来极大的方便 ...
- 【Jmeter自学】Linux环境下Jmeter运行
==================================================================================================== ...
- 【原创】Linux环境下的图形系统和AMD R600显卡编程(1)——Linux环境下的图形系统简介
Linux/Unix环境下最早的图形系统是Xorg图形系统,Xorg图形系统通过扩展的方式以适应显卡和桌面图形发展的需要,然而随着软硬件的发展,特别是嵌入式系统的发展,Xorg显得庞大而落后.开源社区 ...
随机推荐
- spring ext 跨域
read方法中调用的response对象是父类BaseController的一个成员变量. spring默认bean的生命周期Score为singleton单例模式. 当多线程并发使用同一bean, ...
- (转载)让XCode运行时自动更新资源
转自http://goldlion.blog.51cto.com/4127613/1351616 用过XCode的人都知道,XCode有一个臭名昭著的bug——除非你修改了源代码造成了重新编译,否则游 ...
- ios awakeFromNib 和 initWithCoder:
During the instantiation process, each object in the archive is unarchived and then initialized with ...
- Delphi中限制文本框(TEdit)只能输入数字
procedure Tform1.Edit1KeyPress(Sender: TObject; var Key: Char);var edt: TEdit; str, strL, strR: stri ...
- 数学软件 之 基于MATLAB的DFP算法
DFP算法是本科数学系中最优化方法的知识,也是无约束最优化方法中非常重要的两个拟Newton算法之一,上一周写了一周的数学软件课程论文,姑且将DFP算法的实现细节贴出来分享给学弟学妹参考吧,由于博客不 ...
- Angular中使用Rainbow
在使用js类库和框架的时候,大家都习惯于编写自己的使用示例,如果能将示例中的html,js和css 进行展示, 并进行高亮显示,效果会很棒,例如在html高亮显示jquery代码 上面的示例是使用ra ...
- mybatis新增数据后获取自增主键
mybatis对应mysql <insert id="insert" parameterType="com.timestech.wsgk.web.model.Sys ...
- 【leetcode】Sort Colors(middle)☆
Given an array with n objects colored red, white or blue, sort them so that objects of the same colo ...
- C#导出Excel动态列
一.用StreamWrite流对象,导出Excel 1. string _sPath = GenerateSalaryMonthlyReport(dgvSalarySum); System.Diagn ...
- 51nod 1070 Bash游戏 V4 (斐波那契博弈)
题目:传送门. 有一堆个数为n(n>=2)的石子,游戏双方轮流取石子,规则如下: 1)先手不能在第一次把所有的石子取完,至少取1颗: 2)之后每次可以取的石子数至少为1,至多为对手刚取的石子数的 ...