【问题标题】:Yii framework 1.1 get the http request Header in Controller actionYii framework 1.1 在Controller action中获取http请求Header
【发布时间】:2016-06-04 09:21:04
【问题描述】:

API 网址是 www.example.com/api/users?name=test

curl 命令 curl -H "Connection:keep-alive \n User-Agent: Mozilla/5.0 \n Accept:application/json" http://www.example.com/api/users?name=test

API控制器用户action中,如何获取header信息

public function actionUsers()  
    {  
       $this->_checkAuth();  

        // Get Accept type info ???
}

【问题讨论】:

    标签: php curl yii


    【解决方案1】:

    使用CHttpRequest::acceptTypes 其中:

    返回用户浏览器接受类型,如果不存在则返回 null。

    CHttpRequest是默认组件,可以通过Yii::app()->request访问:

    public function actionUsers()  
    {  
        $this->_checkAuth();
        $types = Yii::app()->request->acceptTypes;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 2011-02-15
      • 2015-04-10
      • 2019-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多