Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
登录站点Angularjs,从服务器获取cookie_Angularjs_Http_Cookies_Login - Fatal编程技术网

登录站点Angularjs,从服务器获取cookie

登录站点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:

我正在用angularjs登录网站。这是我的密码:

 $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',
})