1

I'm building a small web server in C++, and I'm trying to add support for POST requests for PHP pages at the moment.

However, I don't know how I should pass the POST request body to the PHP executable. I've seen some examples where environment variables are set and php-cgi is called, but I haven't seen a definitive list of when to set which variables.

If I have the POST body data in a string, what's the best way of executing a POST request on the required PHP file using php-cgi? My setup works for PHP files where no arguments or POST data is sent from the web server to the executable.

1 Answer 1

1

I got it working using the following environment variables:

cmd = "echo \""+req->body()+"\" | "
      "REDIRECT_STATUS=CGI "
      "REQUEST_METHOD=POST "
      "SCRIPT_FILENAME="+uri->src()+" "
      "CONTENT_TYPE=application/x-www-form-urlencoded "
      "CONTENT_LENGTH="+std::to_string(req->body().length())+" "
      "php-cgi";
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.