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
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'];
getallheaders
是 apache_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中放的