【发布时间】:2018-12-08 12:19:12
【问题描述】:
这是我的控制器,我在请求中添加了标头,但我的请求中没有添加标头。
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope, $http) {
$scope.call = function() {
$http({
method: 'POST',
url: 'http://localhost:8081/api/GetData',
headers: {
'token': '33c028f2-6eb6-11e8-ac8b',
'user': 'admin',
'Content-Type': 'application/json'
}
}).then(function(response) {
//$scope.names = response.data;
console.log(response.data);
},
function(response) {
// alert(response.data);
//Second function handles error
$scope.content = "Something went wrong";
}
);
}
});
当我检查我的浏览器控制台时,它没有在请求中显示任何标题。
响应标头 (138 B) 允许 POST、GET、OPTIONS、HEAD 内容长度
0 日期 2018 年 6 月 29 日星期五 10:10:58 GMT 服务器码头 (8.1.15.v20140411)请求标头 (438 B) 接受
text/html,application/xhtml+xm…复制/xml;q=0.9,/;q=0.8
Accept-Encoding gzip, deflate Accept-Language en-US,en;q=0.5
访问控制请求标头内容、令牌、用户
访问控制请求方法 POST 连接保持活动主机
localhost:8081 Origin null User-Agent Mozilla/5.0 (X11; Ubuntu;
Linu…) Gecko/20100101 Firefox/60.0
请帮助我了解为什么我的请求中没有设置标头
【问题讨论】:
-
您使用的是哪个版本的 Angular?
-
确保服务器接受 CORS 策略。如果没有,则永远不会发送标头
标签: angularjs