前端请求js
<script src="angular.min.js"></script>
<script>
angular.module('MyApp', [])
.controller('MainCtrl', function ($scope, $http) {
// 请求的方法
$scope.request = function () {
$http.post(url,
// 请求的数据报文
{
"Mobile": "182****1642",
"Password": "1231231"
},
{
// 这是请求的头信息
headers: {
'Authorization': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUz.eyJzdWIiOjcsImV4cCI6MTUxODc2NDE4MCwiaWF0IjoxNDg3.f0dR6AhKjaykjt60LD1p8RH76n8rXdrXG40'
}
}).then(function (data) {
// 请求成功返回
console.log(data);
}, function (err) {
// 请求失败返回
console.log(err);
})
}
})
</script>
后台接受php
<?php
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');
header('Access-Control-Allow-Headers:WWW-Authenticate,Authorization,Set-Cookie,X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version');
//获取头部信息end
$header = apache_request_headers();
//取head标签内容
var_Dump($header);exit;
?>
打印的数据没有Authorization
,我该如何找到Authorization
。
传的时候有值!
$_SERVER['HTTP_Authorization']
。apache也可能会过滤掉
Authorization
,如果是这种情况要在Apache加配置