|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45503 Content of HTTP POST Message not accessible w/ PHP
Submitted: 2008-07-13 22:03 UTC Modified: 2008-07-22 01:00 UTC
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:3 (100.0%)
From: michael at mcihael-menzel dot com Assigned:
Status: No Feedback Package: HTTP related
PHP Version: 5.2.6 OS: debian linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
33 - 25 = ?
Subscribe to this entry?

 [2008-07-13 22:03 UTC] michael at mcihael-menzel dot com
when recieving POST HTTP messages which have text/xml content in the message body this content can't be accessed:
  - php://input is empty
  - $HTTP_RAW_POST_DATA is empty (though enabled in php.ini)
  - neither do $_POST, $_SERVER and $_REQUEST not contain the data (as expected and correct)
  - neither does $_FILE contain anything (last obvious possibility)
  - even installation of pecl extension pecl_http 1.6 can't solve it (none of the given functions/methods did work)

Reproduce code:
	$headers = getHeaders();

	$ch = curl_init();

	$headers[Host] = ""; # to be filled with a XML webservice URL
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_URL, ""); # to be filled with a XML webservice URL
	curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);

	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("php://input")); # replace with any method/function to get the POST content

	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$httpContent = curl_exec($ch);


	echo $httpContent;
	$h = fopen("responsecontent.log", "a");
	fwrite($h, "\n\n" . $httpContent);

	function getHeaders() {
		$h = fopen("headers.log", "a");
		fwrite($h, "\n\n");
		$headers = array();
		foreach ($_SERVER as $k => $v) {
			if (substr($k, 0, 5) == "HTTP_") {
				$k = str_replace('_', ' ', substr($k, 5));
				$k = str_replace(' ', '-', ucwords(strtolower($k)));
				$headers[$k] = $v;
				fwrite($h, $k . ": " . $v . "\n");

		return $headers;

Expected result:
XML webservice answers to the POST request forwarded with curl.

"reproduce code" doesn't contain the line to test the contents. in the beginning of the script all possible places where the POST content might be placed by PHP are written to a file. 

The file only gets filled by IE requests which send the data in a second HTTP (TCP-, IP-) packet. Firefox sends the whole request with content-type: text/xml in one packet and content is not accessible.

Actual result:
empty response by curl due to the empty post content sent to the webservice


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-14 09:59 UTC]
So the problem is that you can't pass POST stuff to this script? Where's that part in this example? You only included the irrelevant part here, perhaps it would be more obvious if we saw the actual POST form you use.
 [2008-07-22 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 23:01:32 2024 UTC