检查内容类型POST请求PHP

问题描述 投票:2回答:1

如何检查PHP中POST请求的内容类型是application / json还是application / x-www-form-urlencoded?

我曾尝试使用$_SERVER["CONTENT_TYPE"]echo get_headers('url', 1)["Content-Type"],但这些都不适合我。

php header content-type
1个回答
3
投票
echo '<pre>';
print_r(getallheaders());

所以

$allHeaders = getallheaders();
$contentType = $allHeaders['Content-Type'];
© www.soinside.com 2019 - 2024. All rights reserved.