3

Problems with multipart/form-data forced me to parse POST request's parameters manually as I already doing for PUT requests. For that purpose I used this code:

$rawData = file_get_contents('php://input');

But I figured that php://input is always empty for POSTs, at least, for php-fpm SAPI.

Here is some pics from debugger. POST request:

empty $rawData

PUT with same params:

filled $rawData

Is there a way to get raw POST request body? Thanks in advance.

6
  • 2
    In the meanwhile a pointer to PHP man page why raw data is not available for POST php.net/manual/en/wrappers.php.php Commented Nov 22, 2013 at 15:38
  • 1
    RE: the comment above, it IS AVAILABLE for POST request, but it IS NOT AVAILABLE with enctype="multipart/form-data" forms ;) Commented Nov 22, 2013 at 15:40
  • Correct, that's what we're talking about (see the question). Commented Nov 22, 2013 at 15:40
  • 1
    I suggest you give a look to a couple of answers here on SO: (1) stackoverflow.com/questions/19707632/… (2) stackoverflow.com/questions/5561078/… Commented Nov 22, 2013 at 15:41
  • @DavidRiccitelli Sure, i didn't say you were wrong, just hiding the key issue for this question ^^ Commented Nov 22, 2013 at 15:41

2 Answers 2

9

Before PHP 5.4 $HTTP_RAW_POST_DATA is not available with enctype="multipart/form-data" (with the exception of some SAPI implementations), explanations here:

I suggest you give a look to a couple of answers to existing questions:

From PHP 5.4+ you can use the php.ini directive enable_post_data_reading to disable PHP consuming the raw data (hence process it), be aware that $_POST and $_FILES won't be populated though (refer to Vitaly Chirkov answer).

Sign up to request clarification or add additional context in comments.

Comments

0

Could you try

var_dump($HTTP_RAW_POST_DATA);

Source:

http://php.net/manual/en/reserved.variables.httprawpostdata.php

=== Edit - this will not show the raw post data for 'multipart/form-data'

2 Comments

That wouldn't work $HTTP_RAW_POST_DATA is not available with enctype="multipart/form-data": php.net/manual/en/…
Looks like: php://input is not available with enctype="multipart/form-data" also php.net/manual/en/wrappers.php

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.