c++ - [C/C++][CGIcc] GET 有效但 POST 导致错误消息

标签 c++ apache cgi fastcgi

我是 CGI 新手。我使用 Apache v2.2 和 GNU cgicc v3.2.9。我想使用 CGI 生成具有简单表单的 HTML 网页。这项工作的目的是让用户通过点击此 CGI 上的按钮将数据直接发送回“相同”的 CGI。 CGI 评估数据并更改网页:

CGI --> CGI --> CGI --> ...

我不能使用简单的 HTML 页面并将请求发送到 cgi,因为之后我创建了一个 CGI 页面,用户可以再次向该 cgi 发送请求,这会导致与介绍的情况相同:

HTML --> CGI --> CGI --> CGI --> ...

使用表单方法 POST 导致在 GET 工作时出现服务器错误消息:

访问日志

[16/Mar/2011:15:00:50] "GET /cgi-bin/cgiHandleEvents.cgi HTTP/1.1" 200 973

[16/Mar/2011:15:00:52] "GET /cgi-bin/cgiHandleEvents.cgi?value1=&value2=option1&value3=button1&value4=data4 HTTP/1.1" 200 973

[16/Mar/2011:15:01:34] "GET /cgi-bin/cgiHandleEvents.cgi HTTP/1.1" 200 974

[16/Mar/2011:15:01:37] "POST /cgi-bin/cgiHandleEvents.cgi HTTP/1.1" 500 538

error.log (由于关于我的 stackoverflow 声誉的垃圾邮件警告,我将 http://减少为 http//)

[Wed Mar 16 15:01:37 2011] [error] [client 127.0.0.1] Premature end of script headers: cgiHandleEvents.cgi, referer: http//localhost/cgi-bin/cgiHandleEvents.cgi

[Wed Mar 16 15:01:37 2011] [error] [client 127.0.0.1] \r, referer: http//localhost/cgi-bin/cgiHandleEvents.cgi

[Wed Mar 16 15:01:37 2011] [error] [client 127.0.0.1] This application has requested the Runtime to terminate it in an unusual way., referer: http//localhost/cgi-bin/cgiHandleEvents.cgi

[Wed Mar 16 15:01:37 2011] [error] [client 127.0.0.1] Please contact the application's support team for more information.\r, referer: http//localhost/cgi-bin/cgiHandleEvents.cgi

[Wed Mar 16 15:01:37 2011] [error] [client 127.0.0.1] terminate called after throwing an instance of 'std::runtime_error'\r, referer: http//localhost/cgi-bin/cgiHandleEvents.cgi

[Wed Mar 16 15:01:37 2011] [error] [client 127.0.0.1] what(): I/O error\r, referer: http//localhost/cgi-bin/cgiHandleEvents.cgi

当前代码不包含消息处理程序。在我看来,关于 POST,页面应该简单地重新加载。为了检查代码,您可以交换包含不同表单方法的行。

#include "cgicc/CgiDefs.h"
#include "cgicc/Cgicc.h"
#include "cgicc/HTTPHTMLHeader.h"
#include "cgicc/HTMLClasses.h"

using namespace std;
using namespace cgicc;

int main()
{
   Cgicc formData;
   Cgicc cgi;

   cout<< HTTPHTMLHeader() << endl;
   cout<< HTMLDoctype(HTMLDoctype::eStrict) << endl;
   cout<< html().set("lang", "EN").set("dir", "LTR") << endl;

   // Set up the HTML document
   cout<< html() << head() << title("Cgicc example") << head() << endl;
   cout<< body().set("bgcolor","#cccccc").set("text","#000000").set("link","#0000ff").set("vlink","#000080") << endl;

   try
   {
       cout<< h2("Test CGIcc form") << endl;
       cout<< "GNU cgicc v" << cgi.getVersion() << "<BR>" << endl;

       //cout<< "<form method=\"post\" action=\"cgiHandleEvents.cgi\">"<< endl;
       cout<< "<form method=\"get\" action=\"cgiHandleEvents.cgi\">"<< endl;

       cout<< "    Value 1:" << endl;
       cout<< "    <input type=\"text\" name=\"value1\">" << endl;
       cout<< "    <p></p>" << endl;
       cout<< "    Value 2:" << endl;
       cout<< "    <select name=\"value2\">" << endl;
       cout<< "        <option value=\"option1\">Option 1" << endl;
       cout<< "        <option value=\"option2\">Option 2" << endl;
       cout<< "        <option value=\"option3\">Option 3" << endl;
       cout<< "    </select>" << endl;
       cout<< "    <p></p>" << endl;
       cout<< "    Value 3:" << endl;
       cout<< "    <input type=\"radio\" name=\"value3\" value=\"button1\" checked=\"checked\">Button1" << endl;
       cout<< "    <input type=\"radio\" name=\"value3\" value=\"button2\">Button2" << endl;
       cout<< "    <input type=\"hidden\" name=\"value4\" value=\"data4\">" << endl;
       cout<< "    <p></p>" << endl;
       cout<< "    <input type=\"submit\" value=\"Submit\">" << endl;
       cout<< "</form>" << endl;
   }
   catch(exception& e)
   {
       // handle any errors here.
       cout<< h2("ERROR!!!") << endl;
   }
   // Close the HTML document
   cout << body() << html();
   return 0;   // To avoid Apache errors.
}

有人知道问题出在哪里吗?

最佳答案

我知道这是一个很晚的回复,但也许它对某人有帮助。

昨天我第一次开始使用 C++ Cgi 脚本。我发现在使用 POST 方法(GET 工作正常)提交数据时在代码中多次声明 Cgicc 对我也造成了完全相同的问题。通过全局声明 Cgicc 解决了这个问题,因此只在代码中声明了一次。

关于c++ - [C/C++][CGIcc] GET 有效但 POST 导致错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5326732/

相关文章:

java - Apache Lucene createWeight() 用于通配符查询

windows - 当客户端在下载过程中关闭网页时,Perl cgi 脚本仍在运行

javascript - 如何将变量值从 javascript 传递到 perl

linux - 仅 Grep 某些文件

linux - 有没有办法让 ProxyHTMLURLMap 每个标签属性匹配多次?

apache - 防止 mod_jk 在页面加载时显示/附加 index.cfm?&_modcfmlredirected

c++ - 如何在mac终端编译c++程序

c++ - Qt QFile/QTextStream,无法解析/proc/stat

c++ - 删除 vector 中的重复条目

c++ - 将键值表示为枚举