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

标签 c++ cgi

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

相关文章:

c++ - 为什么设计器生成的嵌入为 "Aggregation"的 UI 类无法实现自定义插槽?

c++ - 具体元素数量 - vector

c++ - 初始化期间针对安全检查的指针的常量正确性

php - 我的 nginx 与 spawncgi php 一起运行,POST 和 GET 数据无法通过

python - 什么是 python Web 框架

c++ - 如何同步 CGI 编程?

如果参数包含等号,CGI 脚本不会接收参数

c++ - 模板类继承

c++ - 如何在 std::map 中停止从 int 到 float 的自动转换,反之亦然

linux - 在服务器端使用 bash 代替 PHP/Perl 或 Java