-
Notifications
You must be signed in to change notification settings - Fork 196
[Question] $request->getParsedBody() returns empty array using PUT/PATCH methods #371
Comments
I've tried to use $request->getBody()->getContents() and it shows the body params in string format. I don't know why the getParsedBody() returns an empty array. You may try this: https://gist.github.com/gabbydgab/0193c4b6a8e02f658e9b5f7b7650235d |
It seems it only works with application/json type. |
From the docs (the first link you gave):
|
Even using the body parsing middleware, on POST request the getParsedBody() is not empty, but when PUT request is sent, it's always empty for some reason. |
@gabbydgab Which version of If that's not the issue, let me know and we can investigate further. |
@michaelmoussa Ah, that would make sense since I can't replicate it. I should read the changelogs more often :) |
@gabbydgab The |
Actually... this should work. For people this affects, we need the following information:
|
@ezimuel has indicated that he encountered the problem with $parts = explode(';', $contentType, 2);
$contentType = $parts[0];
// perform match @ezimuel Would you like to prepare a PR? If not, I'll do it next week. |
@weierophinney isn't the strategy as you mentioned in code currently https://github.com/zendframework/zend-expressive-helpers/blob/4aea21e4102661cdafe9ea6d5b45944a68bb8919/src/BodyParams/JsonStrategy.php#L22 . |
Unfortunately, when I send JSON using POST/PUT request and then do My scenario in POSTMAN:
|
@harikt Ooof, you're right. I'll still work up a PR with at least the failing test, though, as it's not working. Something's amiss. @lvidal1 — One issue with |
Creates an integration test to attempt to recreate the problem reported in zendframework/zend-expressive#371. It sets up the following conditions: - A request method that can provide body content - A request body with JSON content - A `Content-Type` request header with the value `application/json;charset=utf-8` It then passes the request to the `BodyParams` middleware, and validates that the request received by the delegate has the parsed contents. Unfortunately... it does not validate the issue reported, as the test passes.
I've created a unit test intended to reproduce the issue... but it doesn't. It passes. If this issue affects you, please look at zendframework/zend-expressive-helpers#43, and let me know if any changes need to be made to the tests proposed. |
Well, I'm really happy to have discovered this thread ! I was really struggling with Following zendframework/zend-expressive-helpers#43, I added |
Thank you for this thread! It took me forever to figure out that I needed to add |
This repository has been closed and moved to mezzio/mezzio; a new issue has been opened at mezzio/mezzio#17. |
I'm having difficulty in parsing the $request->getParsedBody() for PUT/PATCH method - it only returns empty array.
I've enabled Body Parsing Middleware on my controller and it works with POST method.
https://docs.zendframework.com/zend-expressive/features/helpers/body-parse/
I'm trying to implement the REST Controller by Alejandro Celaya
https://blog.alejandrocelaya.com/2016/06/24/dispatch-rest-like-requests-with-a-single-controller-class-in-zend-expressive/
Appreciate your input here. Thanks in advance.
The text was updated successfully, but these errors were encountered: