php thin (explanation of & quot request body & documentation)


I am working with Slim PHP for the first time and I am trying to understand one of the concepts. In the slim PHP documentation, it states:

Request Body

Use the request object’s getBody() method to fetch the raw HTTP request body sent by the HTTP client. This is particularly useful for Slim application’s that consume JSON or XML requests.

$request = $app->request();
$body = $request->getBody();

My question is, what is "the raw HTTP request body"? Is it just a string of all the HTML in the body of the page? What format is it stored as? What would echo $body look like? If I do var_dump($body) I get string(0)"". How do I use it?

I'll just make it an answer rather than comment...

Raw request data is what's submitted from the browser as a body of the POST request.

Technically it can be used to read the data from usual html forms, but this doesn't make much sense as PHP does this good enough and places everything into $_POST.

You may need to read raw data if you have some javascript that sends XML or JSON data, which is not natively accepted by PHP.