所以我使用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"
Run Code Online (Sandbox Code Playgroud)
....
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);
Run Code Online (Sandbox Code Playgroud)
...
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");
}
Run Code Online (Sandbox Code Playgroud)
我已经验证我在请求中传递了一个查询字符串,那么为什么getenv("QUERY_STRING")返回null?我 …