php.net |  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
Votes:3
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-07-13 22:03 UTC] michael at mcihael-menzel dot com
Description:
------------
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);

	curl_close($ch);

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




	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");
			}
		}
		fclose($h);

		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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-07-14 09:59 UTC] jani@php.net
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: Tue Apr 16 20:01:31 2024 UTC