【发布时间】:2015-04-27 06:52:03
【问题描述】:
我正在尝试运行我的第一个 C++ CGI 应用程序。我使用 Ubuntu 14.04 和 Apache 2.4.7。 GET 方法工作正常,问题是当我尝试从 html 表单执行 POST 方法时。浏览器没有得到响应。日志文件如下所示:
apache2/access.log
[25/Feb/2015:10:30:05 +0100] "POST /cgi-bin/cgi-test.cgi HTTP/1.1" 200 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit /537.36(KHTML,如 Gecko)Chrome/40.0.2214.115 Safari/537.36"
apache2/error.log
[2015 年 2 月 25 日星期三 10:30:05.884648] [cgid:error] [pid 1158:tid 139962890278656] (104) 对等方重置连接:[client 127.0.0.1:54871] AH02550:无法将 CGI 输出刷新到客户
POST 表单代码:
<form action="http://localhost/cgi-bin/cgi-test.cgi" method="post">
Test image: <input type="text" name="test"> <br />
<input type="submit" value="Submit" />
</form>
GET 表单代码:
<form action="http://localhost/cgi-bin/cgi-test.cgi" method="get">
Test image: <input type="text" name="test"> <br />
<input type="submit" value="Submit" />
</form>
还有 C++ 代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
int main()
{
std::cout << "Content-type: text/plain\n\n";
char* get_query_data = getenv("QUERY_STRING");
int l_result = -1;
char* lenstr = getenv("CONTENT_LENGTH");
if ( lenstr != NULL )
{
l_result = atoi(lenstr);
}
std::cout << "Post read length: " << l_result <<std::endl;
}
有人知道出了什么问题吗?
【问题讨论】: