登录站点Angularjs,从服务器获取cookie
我正在用angularjs登录网站。这是我的密码:登录站点Angularjs,从服务器获取cookie,angularjs,http,cookies,login,Angularjs,Http,Cookies,Login,我正在用angularjs登录网站。这是我的密码: $scope.signin = function(name) { $http({ method: 'POST', url: 'server_url', data: $.param({action: 'sign_in', username: $scope.username, password:
$scope.signin = function(name) {
$http({
method: 'POST',
url: 'server_url',
data: $.param({action: 'sign_in',
username: $scope.username,
password: $scope.password}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})
.then(function (success) {
$http.get({
method: 'GET',
url: 'server_url',
}).success(function (headers) {
console.log(headers);
})
.error(function (data, status, headers) {
console.log(data, status, headers);
alert(data);
});
});
}
HTML:
登录
在服务器标题中,我在发布正确的用户名和密码后获得cookies,但我不知道如何获得它。我的代码不工作,在我的控制台中有错误:$http:badreq
错误的请求配置
提前感谢asnwers 您的代码无法工作,因为
$http.get
的用法不正确,它与Cookie无关——如果响应中出现设置Cookie
头,Cookie将保存在浏览器中,并将在下次自动发送到服务器
根据AngularJS的说法,$http.get
的用法如下,第一个参数是URL字符串,而不是配置对象:
获取(url,[config])
似乎您需要的是原始$http
,而不是$http。获取快捷方式:
$http({
method: 'GET',
url: 'server_url',
})
可能重复的
$http({
method: 'GET',
url: 'server_url',
})