I'm implementing a REST service in PHP. This service should be able to support multiple input and output formats (JSON, XML). For that reason I want to check the request headers "Accept" and "Content-Type" for the type of content sent and requested by the client.
Accessing the "Accept" header is a simple as using $_SERVER['HTTP_ACCEPT']
. But accessing the "Content-Type" header seems to be a difficult task. I searched the PHP documentation and the web, but the only solution offered was the use of the PHP function apache_request_headers()
which is only supported when PHP is installed as an Apache module, which is not true in my case.
So my question now: How can I access the header "Content-Type" of a request?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…