Yii framework 1.1 get the http request Header in Controller action
The API url is www.example.com/api/users?name=test
the curl command curl -H "Connection:keep-alive n User-Agent: Mozilla/5.0 n Accept:application/json" http://www.example.com/api/users?name=test
in the API controller user action, how to get the header information
public function actionUsers()
{
$this->_checkAuth();
// Get Accept type info ???
}
Use CHttpRequest::acceptTypes
which:
Returns user browser accept types, null if not present.
CHttpRequest
is a default component and can be accessed via Yii::app()->request
:
public function actionUsers()
{
$this->_checkAuth();
$types = Yii::app()->request->acceptTypes;
}
链接地址: http://www.djcxy.com/p/87304.html