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.

Vitaly Chirkov
  • 1,692
  • 3
  • 17
  • 33
  • 2
    In the meanwhile a pointer to PHP man page why raw data is not available for POST http://www.php.net/manual/en/wrappers.php.php – David Riccitelli Nov 22 '13 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 ;) – STT LCU Nov 22 '13 at 15:40
  • Correct, that's what we're talking about (see the question). – David Riccitelli Nov 22 '13 at 15:40
  • 1
    I suggest you give a look to a couple of answers here on SO: (1) http://stackoverflow.com/questions/19707632/php-http-request-content-raw-data-enctype-multipart-form-data (2) http://stackoverflow.com/questions/5561078/userland-multipart-form-data-handler – David Riccitelli Nov 22 '13 at 15:41
  • @DavidRiccitelli Sure, i didn't say you were wrong, just hiding the key issue for this question ^^ – STT LCU Nov 22 '13 at 15:41
  • @DavidRiccitelli so, the answer is there in no way. Why do not you write an answer I can accept? – Vitaly Chirkov Nov 22 '13 at 15:45

2 Answers2

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).

Community
  • 1
  • 1
David Riccitelli
  • 7,491
  • 5
  • 42
  • 56
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'

Bas Kuis
  • 748
  • 1
  • 7
  • 20
  • 3
    That wouldn't work `$HTTP_RAW_POST_DATA is not available with enctype="multipart/form-data"`: http://www.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data – David Riccitelli Nov 22 '13 at 15:38
  • 1
    Looks like: **php://input is not available with enctype="multipart/form-data"** also [php.net/manual/en/wrappers.php](http://us.php.net/manual/en/wrappers.php.php) – Bas Kuis Nov 22 '13 at 15:51