编写第一个CGI程序

来源:互联网 发布:淘宝上卖旅游产品 编辑:程序博客网 时间:2024/05/21 22:47

1.首先确定自己的apache http服务器启动。



服务器还没起来呢


启动服务器



2.编写cgi可执行文件

#include <iostream>int cgi_hello_world(){std::cout<<"Content-type:text/html\r\n\r\n";std::cout<<"<html>\n";std::cout<<"<head>\n";std::cout<<"<title> Hello World -First CGI Program</title>\n";std::cout<<"</head>\n";std::cout<<"<body>\n";std::cout<<"<h2>Hello World ! This is my first CGI program </h2>\n";std::cout<<"</body>\n";std::cout<<"</html>\n";//std::cout<<"</head>\n";return 0;}int main(){    cgi_hello_world();return 0;}


g++ 1.cpp -o cgi_hello_world -g


cgi_hello_world拷贝到apache服务器的cgi-bin目录下



3.访问


浏览器输入http://192.168.1.211:8080/cgi-bin/cgi_hello_world





原创粉丝点击