php://input returns empty

2019-06-22 13:20发布

I have Backbone application. When model updates PUT request goes to my server.

enter image description here

Client-side looks good. But on the server side (PHP) I have some trouble. When I first time test this request in PHPStorm:

file_get_contents('php://input')

return what I expect. But on the other times it always return empty. I restarted Apache - nothing helps.

I know that

Note: A stream opened with php://input can only be read once;

But I thinked that mean one by request. Not once per life :) Where is my mistake?

2条回答
神经病院院长
2楼-- · 2019-06-22 14:07

It was Kohana problem. In Kohana_Request class there is piece of code, that already opened php://input stream

if ($method !== HTTP_Request::GET)
{
    // Ensure the raw body is saved for future use
    $body = file_get_contents('php://input');
}
查看更多
爷的心禁止访问
3楼-- · 2019-06-22 14:19

You should be using $this->request->body() to get the request body.

查看更多
登录 后发表回答