php://input returns empty

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 14:19:17

问题


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

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?


回答1:


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');
}



回答2:


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



来源:https://stackoverflow.com/questions/13546660/php-input-returns-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!