【发布时间】:2012-03-18 08:46:44
【问题描述】:
所以我有一个使用 Light HTTPd 用 C++ 编写的工作 FastCGI 应用程序,但是我无法使用 getenv("QUERY_STRING") 检索查询字符串。如果我取出查询字符串请求(或添加对 null 的检查),一切正常,但在适当的位置它会失败:
#include <stdlib.h>
#ifdef _WIN32
#include <process.h>
#else
#include <unistd.h>
extern char ** environ;
#endif
#include "fcgio.h"
#include "fcgi_config.h" // HAVE_IOSTREAM_WITHASSIGN_STREAMBUF
#include "redisclient.h"
....
while (FCGX_Accept_r(&request) == 0)
{
fcgi_streambuf cin_fcgi_streambuf(request.in);
fcgi_streambuf cout_fcgi_streambuf(request.out);
fcgi_streambuf cerr_fcgi_streambuf(request.err);
...
cout << "Content-type: text/html\r\n"
"\r\n"
"<TITLE>^_^</TITLE>\n"
"<H1>echo-cfpp</H1>\n"
"<H4>PID: " << pid << "</H4>\n"
"<H4>Request Number: " << ++count << "</H4>\n";
// If I make this conditional on getenv("QUERY_STRING") not returning null,
// then the program behaves reliably.
cout <<getenv("QUERY_STRING");
}
我已经验证我在请求中传递了一个查询字符串,那么为什么 getenv("QUERY_STRING") 返回 null? 应该我该怎么做才能找回它?
【问题讨论】: