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

Sphynxinator's avatar

My POST request values returns NULL.

Hi all. I'm trying to POST a value through a REST Application of Chrome. I'm using "Advanced REST Client". The problem is, that I'm posting some values to my link, for example, "example.com/login". And my POST value is like "username:example" and I'm trying to take the POST value from my controller with $request->input('username'); I also tried $request->all() and even $_POST['username']. It returns just null or as invalid index. Yes, I added my link as "/login" to VerifyCSRFToken Middleware except list. Thank you.

0 likes
10 replies
Borisu's avatar

You could check if the field names match in your form. Sometimes a misspelled input name is the culprit.

Sphynxinator's avatar

Thank you for your answer. I don't have any form, because I'm sending the key:value pair directly.

tykus's avatar

Are you POSTing raw JSON; have you structured it correctly:

{
    "key": "value"
}
Cronix's avatar

That image doesn't work.

I added my link as "/login" to VerifyCSRFToken Middleware except list

Try removing the / in that. I don't know if it matters though.

Sphynxinator's avatar

Can you try this link: https://imgur.com/a/ONHzI0V

    $name = $request->input('username');
    $password = $request->input('password');

    echo $name;
    die();

And I'm trying to take the values like this.

Cronix's avatar

What does your controller look like?

tykus's avatar
tykus
Best Answer
Level 104

Use the Body with JSON like I described earlier rather than Variables (they're for something else).

{
    "username": "example_username",
    "password": "example_password"
}

Set the Body Content Type to application/json.

Alternatively, set the Body Content Type to application/x-www-form-urlencoded and specify key/value pairs like you were doing with Variables - this will simulate a HTML form being submitted to the specified URL

Please or to participate in this conversation.