2012-03-22 107 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 ++