Skip to content
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

ServerRequest::getParsedBody always returns empty array #100

Closed
juliardi opened this issue Jan 31, 2019 · 5 comments
Closed

ServerRequest::getParsedBody always returns empty array #100

juliardi opened this issue Jan 31, 2019 · 5 comments

Comments

@juliardi
Copy link

juliardi commented Jan 31, 2019

I am trying to get the request's parsed body using ServerRequest::getParsedBody method, but it always returns an empty array. I've checked the code and do not find the code related to parsing request's body.
Is this the intended behaviour?

@Zegnat
Copy link
Collaborator

Zegnat commented Feb 2, 2019

That sounds wrong. I would expect it to return null or whatever you set it to using ServerRequest::withParsedBody(). Do you have any code that shows the problem?

@Nyholm
Copy link
Owner

Nyholm commented Feb 2, 2019

How do you create the server request? Could you give us 10-20 lines of example code?

@juliardi
Copy link
Author

juliardi commented Feb 3, 2019

I am using the example code from https://github.com/Nyholm/psr7-server/blob/master/README.md.
I'll check my code again to make sure.

@Zegnat
Copy link
Collaborator

Zegnat commented Feb 3, 2019

Nyholm/psr7-server always puts PHP’s $_POST as the parsed body of a request, defaulting to an empty array. It doesn’t do any parsing itself, and will not try to parse non-form encoded requests. (Arguably it should default to null.)

There are a number of middleware available that will parse other types of request content, e.g. Zend includes a JSON parser in their Expressive Helpers.

@juliardi
Copy link
Author

juliardi commented Feb 5, 2019

After checking the request, I found out that the request doesn't include Content-Type: application/x-www-form-urlencoded or Content-Type: multipart/form-data in its header. When the request included one of those headers, ServerRequest::getParsedBody works fine.

@juliardi juliardi closed this as completed Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants