I am attempting to develop simple Peaceful api using FastCGI (and restcgi). After I attempted to implement Publish method I observed the input stream (representing request body) is wrong. Used to do just a little make sure appears like after i attempt to browse the stream only almost every other character is received.

Body sent: name=john&surname=smith Received: aejh&unm=mt

I have attempted more clients simply to make certain it isn't the customer playing using the data. My code is:

int main(int argc, char* argv[]) {
  // FastCGI initialization.
  FCGX_Request request;
  FCGX_InitRequest(&request, 0, 0); 

  while (FCGX_Accept_r(&request) >= 0) {
    // FastCGI request setup.
    fcgi_streambuf fisbuf(request.in);
    std::istream is(&fisbuf);
    fcgi_streambuf fosbuf(request.out);
    std::ostream os(&fosbuf);

    std::string str;
    is >> str;
    std::cerr << str;  // this way I can see it in apache error log

    // restcgi code here

  return 0;

I am using fast_cgi module with apache (unsure in the event that makes any difference).

Any idea what shall we be held doing wrong?

Cheers, Tom

After finding no answer anywhere (not really FastCGI subscriber list) I left the initial fastcgi libraries and attempted using fastcgi++ libraries rather. The issue disappeared. You will find also other benefits - c++, more features, simpler to make use of.

Me is.study() not is >> ...

Sample from restcgi documentation:

clen = strtol(clenstr, &clenstr, 10);
if (*clenstr)
    cerr << "can't parse \"CONTENT_LENGTH="
          << FCGX_GetParam("CONTENT_LENGTH", request->envp)
          << "\"\n";
    clen = STDIN_MAX;

// *always* put a cap on the amount of data that will be read
if (clen > STDIN_MAX) clen = STDIN_MAX;

*content = new char[clen];

is.read(*content, clen);
clen = is.gcount();

I experienced this issue too, with an unmodified Debian install.

I discovered the problem disappeared basically provided a buffer towards the fcgi_streambuf constructor:

const size_t LEN = ... // whatever, it doesn't have to be big.
vector<char> v (LEN);
fcgi_streambuf buf (request.in, &v[0], v.size());
iostream in (&buf);
string s;
getline(in, s); // s now holds the correct data.