So I have a working FastCGI application written in C++ using Light HTTPd, however I'm unable to retrieve the querystring using getenv("QUERY_STRING")
. Everything works fine if I take out the querystring request (or add a check for null), but with that in place it fails:
#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");
}
I've verified that I'm passing a querystring in the request, so why then is getenv("QUERY_STRING") returning null? And what should I be doing to retrieve it?