There was a problem with php: // input. I wanted to write a bot for VK, in the documentation there is the following line:

$data = json_decode(file_get_contents('php://input')); 

But it just does not work. When you try to get something (for example, output via echo or var_dump) it produces NULL. It is logical to add a GET request to the string, and get some kind of answer (I guess so), but still nothing.

Wrote a jQuery test:

 function testVk(){ var markers = {"type":"confirmation","group_id":111,"secret":"test"}; $.ajax({ type: "POST", url: "/sources/vk_bot.php", // data: markers, contentType: "application/json; charset=utf-8", dataType: "json", success: function(data){alert('OK: ' + data);}, failure: function(errMsg) { alert(errMsg); } }); } 

But with this, it leads to a null in response.

Everything is fine in php.ini:

 allow_url_fopen = On 

What else could be wrong? Why am I not getting anything from the stream?

  • You need to check not $data , but file_get_contents('php://input') . There, most likely, the array is already ready, and when you try to decode it, you get NULL. - u_mulder
  • @u_mulder Then the script from the documentation would work without problems. And on var_dump(file_get_contents('php://input')) still produces string (0) "", although a GET request is present in the string. It is always the JSON request that is sent. - Vladimir Gonchar
  • If you send a json - so encode the object into it first. - u_mulder

0