I’m sending a POST request via fetch() from my JavaScript Service-Worker to my TYPO3 Extbase controller action.
The controller then goes on to process the data, but I can’t find a way to get the body data.
I’m calling the Action through an Extbase RouteEnhancer, but I think this shouldn’t affect my Problem.
in the Service Worker: javascript
fetch("myDomain.de/my/route/Enhancer/", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ cookieValue: cookie})
})
public function syncAction()
{
?? Get Body from fetch() here??
return file_get_contents('php://input'); <-- is empty
}
I want to retrieve the body data from fetch.
I’ve tried:
$request = $GLOBALS['TYPO3_REQUEST'];
$data = $request->getParsedBody();
returns NULL
$data = $this->request->getParsedBody();
returns NULL
file_get_contents('php://input');
is empty
Am I missing something?
Is this the right way to approach or may there be a better solution to send the data?
>Solution :
Since TYPO3v11 you can access $this->request for the (decorated) request. This way you can access the request body:
$this->request->getBody()
However, since this will only give you the body as raw stream, you can use this convenience wrapper:
$this->request->getParsedBody()