P
P
paradoks922018-08-21 21:06:46
PHP
paradoks92, 2018-08-21 21:06:46

Why does php post return empty after axios request?

Here is the data sent:

const requestBody = {
                name: 'Akexorcist',
                age: '28',
                position: 'Android Developer',
                description: 'desc',
                awesome: true
            }

            const config = {
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                }
            }

            axios.post('/js/mail.php', requestBody, config)
                .then((response) => {
                console.log(response.data)
            })
        .catch((err) => {
                // Do somthing
            })

Here is console.log(response.data):
Array
(
[name] => Akexorcist
[age] => 28
[position] => Android Developer
[description] => desc
[awesome] => 1
)
And PHP file:
<?php

$body = json_decode(file_get_contents("php://input"), TRUE);
print_r($body);

I've already tried a bunch of things.
Always empty
print_r($body) - outputs nothing
var_dump($body) - outputs NULL

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Nesmeyanov, 2018-08-21
@SerafimArts

How is the "application/x-www-form-urlencoded" header related to json?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question