gpt4 book ai didi

C++ 将 HTML 代码显示为网站(CGI 程序)

转载 作者:行者123 更新时间:2023-11-28 03:19:34 24 4
gpt4 key购买 nike

我希望我解释得对..但我需要我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com