Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MrFiliper's avatar

GET request $request->getContent() is empty

I need to get content (xml) from GET request.

With pure php this works and return xml contant

$content = file_get_contents("php://input");

When i use $request->getContent() in laravel, there is empy request.

0 likes
10 replies
hdsavani's avatar

You can use this way:

$content = $request->all();
1 like
MrFiliper's avatar
$content = $request->all();

Log::info('app.requests', ['request' => $content, 'method' => $request->method()]);

will return empty content too

[2018-05-28 12:22:12] local.INFO: app.requests {"request":[],"method":"GET"} 
hdsavani's avatar

Can you give me your URL link? i think you need to pass like this way as parameters: URL + '?name=test&city=padvadar' etc.

1 like
MrFiliper's avatar

@hdsavani but i can't pass to url, because api sending to my in content

@R3l4x3 Not working

[2018-05-28 12:31:13] local.INFO: app.requests {"request":[],"method":"GET"} 
MrFiliper's avatar

@hdsavani Thats ok, but api send xml content in the header of request and i need to get it from here. I can't change the api.

nolros's avatar

@MrFiliper if I recall you get it as follows:

// no function just key
$var =  $request->key 

which is equal to

echo ($_REQUEST['key']);

///you could also

$var =  $request['key']

Note if it is an API returning XML lets say Pardot then you would parse the curl to xml


$response = new SimpleXMLElement( $pardotApiResponse  );

if ( $response->result) {
       $campaign = $response->result
 }

also worth noting that $name = $request->input('user.name'); only works if e Content-Type header of the request is properly set to application/json

is response coming form an API or form? is a GET or a POST, via curl() or how?

btw, this the request getContent() method.

 /**
     * Returns the request body content.
     *
     * @param bool $asResource If true, a resource will be returned
     *
     * @return string|resource The request body content or a resource to read the body stream
     *
     * @throws \LogicException
     */
    public function getContent($asResource = false)
    {
        $currentContentIsResource = is_resource($this->content);

        if (true === $asResource) {
            if ($currentContentIsResource) {
                rewind($this->content);

                return $this->content;
            }

            // Content passed in parameter (test)
            if (is_string($this->content)) {
                $resource = fopen('php://temp', 'r+');
                fwrite($resource, $this->content);
                rewind($resource);

                return $resource;
            }

            $this->content = false;

            return fopen('php://input', 'rb');
        }

        if ($currentContentIsResource) {
            rewind($this->content);

            return stream_get_contents($this->content);
        }

        if (null === $this->content || false === $this->content) {
            $this->content = file_get_contents('php://input');
        }

        return $this->content;
    }

1 like
MrFiliper's avatar
MrFiliper
OP
Best Answer
Level 1

The problem is in laravel router (web.php). API send POST request to router, but laravel ? transofrm ? request to GET request and all the data disappeared. To resolve the issue i use laravel api router (api.php), there I configure POST request and now it works with $request->getContent().

Thanks all for help! I appreciate it.

1 like

Please or to participate in this conversation.