User tests: Successful: Unsuccessful:
If you want to process raw post data send to an (open) API, you probably would use something similar to this.:
$payload = $this->input->json->getArray();
This is fine when (valid) data was send. In case of an empty request though, a null value is passed to Input::getArrayRecursive()
, which results in the following warning:
Warning: Invalid argument supplied for foreach() in [...]\libraries\src\Input\Input.php on line 165
First, create a test controller "foobar" with the following content in e.g. /components/com_users/controllers/foobar.php
<?php
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
JLoader::register('UsersController', JPATH_COMPONENT . '/controller.php');
class UsersControllerFoobar extends UsersController
{
public function foobar()
{
$payload = $this->input->json->getArray();
print_r($payload);
Factory::getApplication()->close();
}
}
Send a POST request, preferably with the content type "application/json" to that controller / method and leave out the payload / data. It shouldn't matter if you use curl, your browser console and / or an addons to do that.
The expected result would be an empty array.
The warning mentioned above appears.
Status | New | ⇒ | Pending |
Category | ⇒ | Libraries |
Title |
|
Status | Pending | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2020-07-13 17:43:40 |
Closed_By | ⇒ | matrikular | |
Labels |
Added:
?
|