Tutorial :Reading Data From $_POST[] in PHP


I'm trying to read POST data in a PHP script.

My first instincts led me to the $_POST[] array, but for whatever reason, it's never populated.

I'm using HTTP Client for OS X, http://ditchnet.org/httpclient/ to send POST requests. I enter the URL of the script, set the method to POST, set the content-type header to text/plain and then enter myVar=foobar as the body of the request.

I hit send, and there's nothing in the $_POST[] array.

I tried another route after reading some questions here on StackOverflow, and tried reading from the $HTTP_RAW_POST_DATA, but no dice there either. I also tried reading from the php://input stream, and nothing.

As a heads up, I'm able to read from the $_GET[] array if I add some parameters to the URL, but I don't want to do that.

I also need to post the data from a different application, so I can't use the HTML post forms...

Any help would be awesome, thanks guys!


Set the Content-Type header to application/x-www-form-urlencoded. text/plain is not a valid content type for post data.


If you want to read the raw request-body, you can use:



Check to see if post works from a browser... I would suspect the HTTP client you're using is not sending the request properly.

The GET request is considerably simpler than a multipart POST request.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »