esbensp's avatar

Request getContent differs in live and tests

Hey guys,

The class \Illuminate\Foundation\Testing\Concerns\MakesHttpRequests is used by Laravel in test cases so you can test and endpoint (like $this->post) the bug I am facing is that if I call $request->getContent(); in my controller it will return empty string. This only happens in test environments. Normal behaviour of Laravel requests is that getContent will return the raw body of the request.

So to sum up: Request::getContent returns empty string in test environment, but raw body of request in live environment.

Does anybody know how to get the raw body of a request in test environment?

Ref: https://github.com/laravel/framework/issues/31303

0 likes
4 replies
saulsolorzano's avatar

Hi @esbensp I'm facing the same issue and I've spend the last 4 hours trying to figure this out. Did you found a workaround? Thanks!!

saulsolorzano's avatar

Hi! I found the answer, at least for me. I used postJson instead of post and it worked! Hope it helps someone

1 like
rcubitto's avatar

You saved me hours of investigation, thank you sir!

Please or to participate in this conversation.