我目前正在我的大学注册网络应用程序类(class),我们正在学习 cgi 脚本。我很难学习如何实现我的 CGI 脚本。当我点击我的链接时,会弹出一个窗口要求我下载我的 helloworld.cgi 文件,而不是仅仅重定向。
HTML:
<html>
<body>
<a href="/user/local/apache2/cgi-bin/helloworld.cgi">click me</a>
</body>
</html>
C++:
#include <iostream>
using namespace std;
int main(){
cout << "Content-type: text/html" << endl;
cout << "<html>" << endl;
cout << " <body>" << endl;
cout << " Hello World!" << endl;
cout << " </body>" << endl;
cout << "</html>" << endl;
return 0;
}
CGI脚本存放在/user/local/apache2/cgi-bin/helloworld.cgi
最佳答案
您需要编译C++文件,并调用结果helloworld.cgi。 C++ 不是脚本语言——您不能只将它部署到您的服务器。
在典型的 *nix 系统上,将 C++ 文件命名为 helloworld.cpp
gcc -o helloworld.cgi helloworld.cpp
然后将该文件放入您的cgi-bin
编辑:在最后一个标题项之后需要两个 endl
cout << "Content-type: text/html" << endl << endl;
关于c++ - 如何使用 C++ CGI 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4824273/