我希望我解释得对..但我需要我的 C++ 程序来显示 HTML 网站。我现在拥有的代码仅显示文本。我如何制作它才能像网站一样实际显示(使用 HTML 代码)?我将使用上传到服务器的 .exe 文件来显示页面。
#include <iostream>
using namespace std;
int main()
{
cout << "Content-type: text/plain\n\n";
cout << "<h2>My first CGI program</h2>\n";
cout << "<h1>This is a test</h1>\n";
cout << "<h3>Why is this not working</h3>\n";
return 0;
}
最佳答案
您的 HTTP 响应需要状态行,您应该将 mime 类型更改为 text/html
:
cout << "HTTP/1.1 200 OK\n";
cout << "Content-Type: text/html\n\n";
cout << "<h2>My first CGI program</h2>\n";
cout << "<h1>This is a test</h1>\n";
cout << "<h3>Why is this not working</h3>\n";
关于C++ 将 HTML 代码显示为网站(CGI 程序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15857094/