2012-03-22 146 views
1

我甚至无法得到一个简单的CGI测试程序。这是我的代码。它的工作原理,当我在控制台中运行,但给人的错误,当我尝试从运行Apache:脚本标题提前结束:CGI + C++

#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 
+4

HTTP行尾'\ r \ N'。 – 2012-03-22 23:21:00

+0

@KerrekSB:我想知道区别。任何进一步的阅读呢? – Straseus 2012-03-22 23:25:51

+0

没有比该行的末尾更进一步:-)但严重的是,这只是协议规范的一部分。如果你敢,你可以阅读RFC。 – 2012-03-22 23:28:47

回答

1

解决:生成文件:

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

GCC不G ++

相关问题