I am sending a request to a php server with a XML in the content:
POST /index3.php HTTP/1.0
Connection: Close
Accept: application/xml
Content-Type: text/xml
<?xml version="1.0" encoding="UTF-8"?>
<root />
I've checked in globals vars (like $_GET
, $_POST
, $_ENV
, $_FILES
, $_REQUEST
...) but they are all empty.
How could I retrieve the content in the server?
To retrieve the body of the POST request sent to the handler, we'll use the @RequestBody annotation, and assign its value to a String. This takes the body of the request and neatly packs it into our fullName String. We've then returned this name back, with a greeting message.
So, yes, you can send a body with GET, and no, it is never useful to do so. This is part of the layered design of HTTP/1.1 that will become clear again once the spec is partitioned (work in progress). Yes, you can send a request body with GET but it should not have any meaning.
PHP $_REQUEST is a PHP super global variable which is used to collect data after submitting an HTML form. The example below shows a form with an input field and a submit button. When a user submits the data by clicking on "Submit", the form data is sent to the file specified in the action attribute of the <form> tag.
Try this
$xml = file_get_contents('php://input');
From the manual:
php://input is a read-only stream that allows you to read raw data from the request body.
Use file_get_contents("php://input")
(manual).
In PHP older than 7.0 you could also use $HTTP_RAW_POST_DATA
(depending on always_populate_raw_post_data setting).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With