Reputation: 271
How can I check if the Content-type of a POST request in PHP is either application/json or application/x-www-form-urlencoded?
I've tried using $_SERVER["CONTENT_TYPE"]
and echo get_headers('url', 1)["Content-Type"]
but neither of those work for me.
Upvotes: 3
Views: 6246
Reputation: 187
It's working below codes. You can try it
$headerArray = getallheaders();
$contentType = $headerArray['Content-Type'];
(Or)
$contentType = $_SERVER["CONTENT_TYPE"];
(Or)
$headerArray = apache_request_headers();
$contentType = $headerArray['Content-Type'];
Upvotes: 1
Reputation: 394
echo '<pre>';
print_r(getallheaders());
So
$allHeaders = getallheaders();
$contentType = $allHeaders['Content-Type'];
Upvotes: 6