【问题标题】:Apache error with C CGI programC CGI程序的Apache错误
【发布时间】:2014-12-15 10:52:25
【问题描述】:

我正在尝试用 C 编写一个 CGI 程序(我正在学习,这似乎很有趣),我遇到了 Apache/CGI 错误的问题,但只有一个非常具体的行。如果此特定行被注释或删除,它工作得很好,但如果它被包含,它每次都会炸弹。

struct site_link
{
    char *name;
    char *url;
};

struct blog_data
{
    char *blog_name;
    struct site_link *links;
} blog;

blog.blog_name = "richardwagner.io";
blog.links[0].url = "Home"; // <-- this line right here
blog.links[0].name = "Home";
blog.links[1].url = "Posts";
blog.links[1].name = "Posts";
blog.links[2].url = "About";
blog.links[2].name = "About";

并且开启了“调试”级别日志记录的 Apache 日志。

[Mon Dec 15 10:27:38.906961 2014] [authz_core:debug] [pid 63010] mod_authz_core.c(799): [client 192.168.1.104:49922] AH01626: authorization result of Require all granted: granted
[Mon Dec 15 10:27:38.906982 2014] [authz_core:debug] [pid 63010] mod_authz_core.c(799): [client 192.168.1.104:49922] AH01626: authorization result of <RequireAny>: granted
[Mon Dec 15 10:27:38.907020 2014] [authz_core:debug] [pid 63010] mod_authz_core.c(799): [client 192.168.1.104:49922] AH01626: authorization result of Require all granted: granted
[Mon Dec 15 10:27:38.907026 2014] [authz_core:debug] [pid 63010] mod_authz_core.c(799): [client 192.168.1.104:49922] AH01626: authorization result of <RequireAny>: granted
[Mon Dec 15 10:27:39.186804 2014] [cgi:error] [pid 63010] [client 192.168.1.104:49922] End of script output before headers: tblog

几天来我一直在尝试解决这个问题,但我无法让它与那一行很好地配合,尽管对我来说,它似乎与它下面的其他几行几乎相同。

【问题讨论】:

  • 我知道我会忘记一些事情。在这之前我也有 Content-type blah-blah 行。

标签: c apache cgi


【解决方案1】:

您缺少 \r\n\r\n 来表示标题的结尾。

【讨论】:

  • 如:printf("Content-type: text/html\r\n\r\n"); //???产生和记录的错误是一样的。
  • 在命令行上运行 CGI 并将输出放入 pastebin/gist
猜你喜欢
  • 1970-01-01
  • 2012-08-09
  • 2015-05-22
  • 1970-01-01
  • 1970-01-01
  • 2012-10-28
  • 1970-01-01
  • 1970-01-01
  • 2012-12-13
相关资源
最近更新 更多