【问题标题】:Premature end of script headers: CGI + C++脚本头过早结束:CGI + C++
【发布时间】:2012-04-07 14:04:20
【问题描述】:

我什至无法获得一个使用 CGI 的简单测试程序。这是我的代码。当我在控制台中运行它时它可以工作,但是当我尝试从 Apache 运行时会出现错误:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

int main() {
    printf("Content-type: text/html\n\n");
    printf("TEST");
    return 0;
}

制作文件:

build: source/main.cpp
    C:/MinGW/bin/g++.exe -o build/e2.exe source/main.cpp

错误:

[Thu Mar 22 19:14:23 2012] [error] [client 127.0.0.1] Premature end of script headers: e2.exe

在命令提示符下运行:

C:\Users\Stephen>C:\wamp\www\e2.exe
Content-type: text/html

TEST

任何帮助将不胜感激!谢谢!

已解决:生成文件:

build: source/main.cpp
    C:/MinGW/bin/gcc.exe -o build/e2.exe source/main.cpp

【问题讨论】:

  • HTTP 行结尾是\r\n
  • @KerrekSB:我想知道区别。有什么进一步的阅读吗?
  • 不超过行尾 :-) 但说真的,这只是协议规范的一部分。如果你敢,你可以阅读 RFC。
  • 当一些很酷的人可以为您总结时,为什么还要阅读 RFC:stackoverflow.com/a/5757349/1210546
  • MinGW 不使用 Windows 样式的行尾吗?由于 OP 在 Windows 上运行,\n 应转换为 CRLF。我已经检查过 dev-c++ (不记得哪个是后面的 C++ 编译器),并使用 printf("abc\n\n");给了我两个 CRLF,而 printf("abc%c%c",13,13);只给我两个 CR。

标签: c++ apache cgi


【解决方案1】:

已解决:生成文件:

build: source/main.cpp
    C:/MinGW/bin/gcc.exe -o build/e2.exe source/main.cpp

GCC 不是 G++

【讨论】:

    猜你喜欢
    • 2012-06-25
    • 2021-12-03
    • 2011-03-19
    • 2012-06-09
    • 2014-06-03
    • 1970-01-01
    • 2012-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多