Home  >  Article  >  Backend Development  >  Swift - Please give me an answer on how to receive the output number of the header in the request on the ios side in PHP

Swift - Please give me an answer on how to receive the output number of the header in the request on the ios side in PHP

WBOY
WBOYOriginal
2016-09-22 08:56:471160browse

Alamofire.request(.POST, "http://srxapp.zkkd.com/ios.php/Login/login", headers: ["token":token]).responseJSON { (data) in

<code>    let json = JSON(data: data.data!)
    print(json)
}


php端怎么接受 headers 里面的 token值呢</code>

回复内容:

Alamofire.request(.POST, "http://srxapp.zkkd.com/ios.php/Login/login", headers: ["token":token]).responseJSON { (data) in

<code>    let json = JSON(data: data.data!)
    print(json)
}


php端怎么接受 headers 里面的 token值呢</code>

$_SERVER['HTTP_TOKEN']

getallheaders()['token'];

getallheadersapache_request_headers 的别名,不能用于 nginx 服务器,自己简单写一个function 获取。

<code>function request_header($key = null)
{
    $all_headers = [];
    foreach ($_SERVER as $name => $value) {
        if (substr($name, 0, 5) == 'HTTP_') {
            $all_headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
        }
    }

    return is_null($key) ? $all_headers : (isset($all_headers[$key]) ? $all_headers[$key] : null);
}
request_header('token'); // 不传key返回所有heads数组</code>

所有请求数据都在$_REQUEST中放的

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn