一般的网关接口或者CGI,就是一个标准的集合。它定义信息怎样再问吧server和一般脚本间的交换。

CGI的说明书是由NCSA维护,NCSA定义CGI的范畴:一般的网关接口或者CGI是外部网关程序的一个标准,它与信息server交互。当前的CGI版本号是CGI/3.2.9,兴许版本号还在开发中。

一般的网关程序(CGI)是一个标准协议,它可以使应用程序(称之为CGI程序或者CGI脚本)与Webserver和client进行交互。

这些CGI程序可以使用Python、PERL、Shell,C或者C++等编写。

以下介绍一个实例,依据这个实例来说明,怎样使用CGI。

首先,必须配置HTTPserver,这里。我们选择ApacheHttpd作为HTTP协议的server。CGI设置例如以下:

#change the directoryRootvariable in httpd.conf file
DocumentRoot"/usr/local/apache-2.4.9/htdocs"
#set theaccess control
<Directory"/usr/local/apache-2.4.9">

#enable the cgi module
LoadModule cgid_module modules/mod_cgid.so
#set the directoryproperties
<Directory "/usr/local/apache-2.4.9/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory> <Directory "/usr/local/apache-2.4.9/cgi-bin">
Options All
</Directory>

编写一个C++的CGI程序,并编译它得到cpp.cgi文件。改变这个文件的全部权限,使用命令“chmod 755 cpp.cgi”。

cpp.cpp文件

#include <iostream>
using namespace std; int main ()
{ cout << "Content-type:text/html\r\n\r\n";
cout << "<html>\n";
cout << "<head>\n";
cout << "<title>C++ CGI Welcome you</title>\n";
cout << "</head>\n";
cout << "<body>\n";
cout << "<h2>Congratulation, you enter into the world of CGI.</h2>\n";
cout << "</body>\n";
cout << "</html>\n"; return 0;
}

将编译后的cgi文件放置指定的路径(/usr/local/apache-2.4.9/cgi-bin)下。启动httpd服务。浏览页面:

http://hadoop-master/cgi-bin/cpp.cgi

版权声明:本文博客原创文章。博客,未经同意,不得转载。

C++ Web Programming的更多相关文章

  1. Introduction to ASP.NET Web Programming Using the Razor Syntax (C#)

    1, http://www.asp.net/web-pages/overview/getting-started/introducing-razor-syntax-c 2, Introduction ...

  2. Web开发中最致命的8个小错误

    错误1:表单的label标签跟表单字段没有关联 利用“for”属性允许用户单击label也可以选中表单中的内容.这可以扩大复选框和单选框的点击区域,非常实用. 错误2:logo图片没有链接到主页 点击 ...

  3. java web 学习 --第十天(Java三级考试)

    第九天学习内容:http://www.cnblogs.com/tobecrazy/p/3470195.html 需求概述 创建程序模块,读取并显示数据库中的书籍信息.当前有如下需求:需要显示数据库中所 ...

  4. web server && web framework角色区分

    问题 web framework是否包括webserver? 是否可以包括? webserver 和 framework的关系是? https://www.quora.com/What-is-the- ...

  5. [译]如何在Web开发中使用Python

    [译]如何在Web开发中使用Python 原文:HOWTO Use Python in the Web 摘要 这篇文档展示了Python如何融入到web中.它介绍了几种Python结合web服务器的方 ...

  6. Go Web:处理请求

    处理请求 Request和Response http Requset和Response的内容包括以下几项: Request or response line Zero or more headers ...

  7. Go Web:Cookie

    Cookie用来解决http协议无状态的问题. 首先,在服务端生成Cookie,然后在http响应header中设置Set-Cookie字段,客户端会读取到Set-Cookie字段后,会将cookie ...

  8. Mercedes offline programming/coding tips and guides

    Mercedes offline programming/coding recommendations and guides: Offline coding: SCN or CVN coding wa ...

  9. Programming Languages: Application and Interpretation

    http://cs.brown.edu/courses/cs173/2012/book/ 1 Introduction 1.1 Our Philosophy 1.2 The Structure of ...

随机推荐

  1. lua5.1 和 5.2 关于 sequence 的定义变化,对#table取值的影响

    引子 环境 lua 5.2 a = {}   for i=1,2 do a[i] = i*3 end   a[4] = 11;   print(a[#a])   ---print 11 ------- ...

  2. Spring它不支持依赖注入static静态变量

    在springframework在,我们不能@Autowired静态变量,制作spring bean,例如,没有那么: @Autowired private static YourClass your ...

  3. MVC @Html控件

    传统的Html元素不能和服务端数据进行绑定 HtmlHelper类提供了一系列的方法来生成Html元素 并可以实现与数据绑定在一起 然后生成Html Html.BeginForm(actionName ...

  4. [转]Qt 智能指针学习

    从内存泄露开始? 很简单的入门程序,应该比较熟悉吧 ^_^ #include <QApplication> #include <QLabel> int main(int arg ...

  5. GDB十几分钟教程

    GDB十分钟教程 作者: liigo原文链接: http://blog.csdn.net/liigo/archive/2006/01/17/582231.aspx日期: 2006年1月16日 本文写给 ...

  6. 谈谈CListCtrl 扩展风格设置方法-SetExtendedStyle和ModifyStyleEx 比較

    谈谈CListCtrl 扩展风格设置方法 --------------------------------------SetExtendedStyle和ModifyStyleEx 比較 对于刚開始学习 ...

  7. Channel Allocation (poj 1129 dfs)

    Language: Default Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12 ...

  8. [LeetCode228]Summary Ranges

    题目: Given a sorted integer array without duplicates, return the summary of its ranges. For example, ...

  9. 【C语言探索之旅】 第二部分第九课: 实战"悬挂小人"游戏 答案

    内容简介 1.课程大纲 2.第二部分第九课: 实战"悬挂小人"游戏 答案 3.第二部分第十课预告: 安全的文本输入 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题, ...

  10. Java中判断字符串是否为数字的五种方法 (转)

    推荐使用第二个方法,速度最快. 方法一:用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = str.length( ...