请求选项并发布

时间:2018-09-27 19:07:25

标签: angular http http-headers

我正在尝试在登录页面中实现令牌。 后端返回一个OPTIONS响应和一个POST响应。

我的问题是OPTION不保存它,并且当我的前端处理响应时,由于某种原因我的令牌为空。

Request URL: http://10.129.194.145:7020/PrecisionServices/login
    Request Method: OPTIONS
    Status Code: 200 OK
    Remote Address: 10.129.194.145:7020
    Referrer Policy: no-referrer-when-downgrade
    Access-Control-Allow-Headers: Authorization, Content-Type, Accept, x-requested-with, Cache-Control
    Access-Control-Allow-Methods: POST, GET, OPTIONS
    Access-Control-Allow-Origin: *
    Access-Control-Max-Age: 3600
    Content-Length: 0
    Date: Thu, 27 Sep 2018 19:03:26 GMT
Request URL: http://10.129.194.145:7020/PrecisionServices/login
Request Method: POST
Status Code: 200 OK
Remote Address: 10.129.194.145:7020
Referrer Policy: no-referrer-when-downgrade

Access-Control-Allow-Headers: Authorization, Content-Type, Accept, x-requested-with, Cache-Control
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Origin: *
Access-Control-Max-Age: 3600
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI4MDQ5NDE3MCIsImV4cCI6MTUzODA3NzM2N30.Qq5CsPaIHjF-7cLt7bjVm4idEQ73xSAeguoqYAquulVqW-uuNIBr2UjJEOsKKfVZcrHYDem1Nly15INIcAdxEg
$http({
            method: 'POST',
            url: config.service_base + 'login',
            headers: {
                'Content-Type': 'application/json',
            },
            data: {
                user: factory.data.username,
                passwd: factory.data.password
            },
        }).then(function(response) {
            console.log(response);
            layoutFactory.locker('doing-login', false);

            if (response.status == 200) {
                var token = response.headers('Authorization');

                if (token != null){
                    window.localStorage.setItem('token', token.replace('Bearer ',''));
                }

                factory.getMenu();
            }

有没有猜到? 谢谢

0 个答案:

没有答案