Problem
When using jQuery $.ajax to dispatch an HTTP POST request, the current approach does not properly detect this as being a HTTP POST request and $request->getParsedBody() remains empty, while $request->getBody() contains content like parameter1=value1¶meter2=value2¶meterN=valueN.
Workaround
Currently the following workarounds can be considered:
use ZendExpressive Body Parsing Middleware which does properly detect the HTTP POST request when the ContentType is application/x-www-form-urlencoded; charset=UTF-8, but this requires the complete set of Zend-Expressive Middleware helpers to be installed.
explicitly set the $.ajax ContentType to application/x-www-form-urlencoded
Context Currently, HTTP POST request parameters are detected when the ContentType of the HTTP Request equals either
application/x-www-form-urlencoded
ormultipart/form-data
. After this "detection", they can be access using$request->getParsedBody()
.When using jQuery $.ajax to dispatch an HTTP POST request, the default ContentType of the HTTP Request is
application/x-www-form-urlencoded; charset=UTF-8
, which is valid syntax for this header.Problem When using jQuery $.ajax to dispatch an HTTP POST request, the current approach does not properly detect this as being a HTTP POST request and
$request->getParsedBody()
remains empty, while$request->getBody()
contains content likeparameter1=value1¶meter2=value2¶meterN=valueN
.Workaround Currently the following workarounds can be considered:
application/x-www-form-urlencoded; charset=UTF-8
, but this requires the complete set of Zend-Expressive Middleware helpers to be installed.application/x-www-form-urlencoded
Possible solution Maybe the current exact match for
application/x-www-form-urlencoded
can be loosened a bit? At least this is how theFormUrlEncodedStrategy
of the BodyParsingMiddleware does itA more robust / future proof approach might be to adopt a similar "strategy" mechanism as the BodyParsingMiddleware, which also has a strategy for detecting JSON payloads, also see https://github.com/zendframework/zend-expressive-helpers/tree/master/src/BodyParams