apache - PHP: How to read POST body with Transfer-Encoding: chunked, no Content-Length -
i writing service receive data energy monitoring device in house. way device can push data using http post
, transfer-encoding: chunked
, , no content-length
, , data xml in request body.
i able read data in php script (behind apache) , store in database.
it appears correct way read http request body in php these days open , read php://input
. however, comments users on php's website indicate (and testing confirms), if no content-length
header specified client, php://input
returns no data (even if there data being sent client in chunked encoding).
is there alternate way access request body? can configure apache (with .htaccess) decode chunked data , call script once gets all, , include content-length
? or configure php able handle this?
thanks!
might write answer suppose.
the issue describe documented here: https://bugs.php.net/bug.php?id=60826
highlights thread:
so here found. if send chunked http request not send content-length (as should using http 1.1 protocol) body part of request empty (php://input returns nothing). result remains valid following configuration php runs via fastcgi :
the same configuration php running mod_php fine, body request available through php://input.
and
essentially, php following spec, , not reading beyond fastcgi content_length header value - correct fixes above php, in fastcgi or web server implementation.
possible workarounds:
0) use httpd mod_php
1) use different web server.
2) @ patches mod_fcgid
3) maybe (not recommended) flip always_populate_raw_post_data
, see if there in $http_raw_post_data
Comments
Post a Comment