Linux环境下使用C/C++编写CGI(httpd)
2015-07-18 03:03
507 查看
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:
View Code
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
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:
#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; } return 0; // To avoid Apache errors. }
View Code
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
相关文章推荐
- WebService接口与HTTP接口的联系
- 黑马程序员----java网络编程基础
- 一次对HTTPS页面抓取的报错发现过程
- 请解释下列HTTP状态码的含义:201、301、401、403、500、503。
- Http API笔记
- Volley完全解析
- linux网络编程之udp的connect趣谈
- 神经网络(Neural Networks,NN)
- Cisco网络方面的书籍
- OkHttp使用进阶 译自OkHttp Github官方教程
- 基于三层网络的音频传输技术
- HttpServlet 笔记
- Linux网络接口配置文件ifcfg-eth0解析
- sk_buff结构分析
- 黑马程序员----网络编程
- 超级详细Tcpdump 的用法
- Vmware虚拟机网络模式及虚拟机与物理机通信方法
- linux系统网络命令(五)
- 单例模式的应用___网络电视精灵
- Reachability用于在任何地方判断网络是否可用