C++ Web Programming

时间:2023-03-10 02:36:42
C++ Web Programming

C++ Web Programming

一般的网关接口或者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

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