一般的网关接口或者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. not accessible due to restriction on required library

    The type AWTUtilities is not accessible due to restriction on required library D:\Program Files\jdk1 ...

  2. android imageButton 透明图片

    在Android有许多不规则button.例如: 这个时候,我们假设想做成不规则button的话.第一步就是搞一张边缘透明的png图片,然后用src指定到他.这个时候我们会发现,还没有达到要的效果.还 ...

  3. C++ - 内置类型的最大值宏定义

    内置类型的最大值宏定义 本文地址: http://blog.csdn.net/caroline_wendy/article/details/24311895 C++中, 常常会使用, 某些类型的最大值 ...

  4. CSA 第五届研讨会 想象

    参加第五届CSA云安全联盟研讨会. 人们太.所以,我们没有找到座位.立一个很长的时间.为了弥补没有时间坐在办公室.一个补回来.首先为大家介绍的信贷云,事实上独立: 信-使用-云 1. 信-使用-云 什 ...

  5. 【C++探索之旅】开宗明义+第一部分第一课:什么是C++?

    内容简介 1.课程大纲 2.第一部分第一课:什么是C++? 3.第一部分第二课预告:C++编程的必要软件 开宗明义 亲爱的读者,您是否对C++感兴趣,但是C++看起来很难,或者别人对你说C++挺难的, ...

  6. Unity3D 表对象分类中的实现(C#)

    // Sort by distance in descending order private void SortTargetsByDistance () { targets.Sort(delegat ...

  7. 参加persist.sys物业写权限的方法

    1.于AndroidManifest.xml manifest添加属性android:sharedUserId="android.uid.system" 2.假设AndroidMa ...

  8. 【iOS开发-21】UINavigationController导航控制器初始化,导航控制器栈的push和pop跳转理解

    (1)导航控制器初始化的时候一般都有一个根视图控制器,导航控制器相当于一个栈,里面装的是视图控制器,最先进去的在最以下,最后进去的在最上面.在最上面的那个视图控制器的视图就是这个导航控制器对外展示的界 ...

  9. LeetCode之Sort List

    称号:Sort a linked list in O(n log n) time using constant space complexity. 对一个单链表进行排序,要求时间复杂度为O(n log ...

  10. 【C++基金会 06】explictkeyword

    C++提供keywordexplicit,你应该不能阻止的转换构造隐式转换发生的同意.声明explicit的构造不能在一个隐式转换使用. 1.演示样例 我们先来看一段演示样例代码: class A { ...