Как получить тело POST на php?

Я отправляю как POST на страницу php следующее:

{a:1}

Это тело запроса (запрос POST).
Что мне нужно сделать в php, чтобы извлечь это значение?

var_dump($_POST); 

не решение, не работает.

242
задан rdlowrey 24 October 2012 в 10:09
поделиться

1 ответ

function getPost()
{
    if(!empty([110]POST))
    {
        // when using application/x-www-form-urlencoded or multipart/form-data as the HTTP Content-Type in the request
        // NOTE: if this is the case and [110]POST is empty, check the variables_order in php.ini! - it must contain the letter P
        return [110]POST;
    }

    // when using application/json as the HTTP Content-Type in the request 
    $post = json_decode(file_get_contents('php://input'), true);
    if(json_last_error() == JSON_ERROR_NONE)
    {
        return $post;
    }

    return [];
}

print_r(getPost());
0
ответ дан 23 November 2019 в 03:12
поделиться
Другие вопросы по тегам:

Похожие вопросы: