New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] $request->getParsedBody() returns empty array using PUT/PATCH methods #17
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 Originally posted by @gabbydgab at zendframework/zend-expressive#371 (comment) |
It seems it only works with application/json type. See zendframework/zend-expressive-helpers#19 Originally posted by @gabbydgab at zendframework/zend-expressive#371 (comment) |
From the docs (the first link you gave):
Originally posted by @geerteltink at zendframework/zend-expressive#371 (comment) |
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. Originally posted by @loter at zendframework/zend-expressive#371 (comment) |
@gabbydgab Which version of If that's not the issue, let me know and we can investigate further. Originally posted by @michaelmoussa at zendframework/zend-expressive#371 (comment) |
@michaelmoussa Ah, that would make sense since I can't replicate it. I should read the changelogs more often :) Originally posted by @geerteltink at zendframework/zend-expressive#371 (comment) |
@gabbydgab The Originally posted by @ezimuel at zendframework/zend-expressive#371 (comment) |
Actually... this should work. For people this affects, we need the following information:
Originally posted by @weierophinney at zendframework/zend-expressive#371 (comment) |
@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. Originally posted by @weierophinney at zendframework/zend-expressive#371 (comment) |
@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 . Originally posted by @harikt at zendframework/zend-expressive#371 (comment) |
Unfortunately, when I send JSON using POST/PUT request and then do My scenario in POSTMAN:
Originally posted by @lvidal1 at zendframework/zend-expressive#371 (comment) |
@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 Originally posted by @weierophinney at zendframework/zend-expressive#371 (comment) |
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. Originally posted by @weierophinney at zendframework/zend-expressive#371 (comment) |
Well, I'm really happy to have discovered this thread ! I was really struggling with Following zendframework/zend-expressive-helpers#43, I added Originally posted by @jbelien at zendframework/zend-expressive#371 (comment) |
Thank you for this thread! It took me forever to figure out that I needed to add Originally posted by @ramsey at zendframework/zend-expressive#371 (comment) |
I suggest closing this issue as the final comment covers the correct resolution. |
@spacedog4 please create a new issue instead, but the explanation you gave so far is a bit vague. |
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.
Originally posted by @gabbydgab at zendframework/zend-expressive#371
The text was updated successfully, but these errors were encountered: