編寫第一個CGI程序

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





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章