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
Release: 2016-09-22 08:56:47
Original
1139 people have browsed it

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>
Copy after login
Copy after login

回复内容:

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>
Copy after login
Copy after login

$_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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!