1

使用.Zend\Mvc\Controller\AbstractRestfulController#requestHasContentType(...)检查内容$request->getHeaders()->get('content-type');

现在我正在发送这样的 cURL 请求:

# curl -i http://project.dev/seminars/1 -H 'Accept: allication/xml'
HTTP/1.1 200 OK
Date: Fri, 14 Jun 2013 16:06:33 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze15
Vary: Accept-Encoding
Content-Length: 1108
Content-Type: text/html

所以,内容类型是text/html. 但是我得到的输出是false

$test = $this->getRequest()->getHeaders()->get('content-type');
var_dump($test);
// output: bool(false)

为了获得 REST 请求的内容类型,我做错了什么,我应该怎么做?


我的错 - 我期待Accept. $request->getHeaders()->get('content-type')而不是它,我应该使用$this->getRequest()->getHeaders()->get('Accept').

4

0 回答 0