为什么angular.js上的响应不包含某些标题?

时间:2022-06-20 12:30:27

First of all, i'll give you img with POSTMAN tests (at the end of this question you'll fild google drive with postman.png)

首先,我会给你img POSTMAN测试(在这个问题的最后,你将使用postman.png与google驱动器相结合)

My problem: there are client on angular.js and laravel api (without access to config and code)

我的问题:angular.js和laravel api上有客户端(无法访问配置和代码)

I want build JWT Auth on client When I send data to api, angular.js send first request - OPTION - (at the end of this question you`ll fild google drive with angular-option.png)

我想在客户端上构建JWT Auth当我向api发送数据时,angular.js会发送第一个请求 - OPTION - (在这个问题的最后你将使用angular-option.png来推动google驱动器)

After OPTIONS - POST request (at the end of this question you'll fild google drive with POST-1.png and POST-2.png) You see, that in response header i have Authorization key with my token, but when I log() request and respone on client, i havenot this header - (at the end of this question you'll fild google drive with response-client.png)

在OPTIONS - POST请求之后(在这个问题的最后你将使用POST-1.png和POST-2.png来推动google驱动器)你看,在响应头中我有我的令牌的授权密钥,但是当我登录时()请求并在客户端上重新开始,我没有这个标题 - (在这个问题的最后你将使用response-client.png来推动谷歌驱动器)

Why in this response there isn't header Authorization?

为什么在这个响应中没有头文件授权?

Link to Google Drive

链接到Google云端硬盘

There is my code

有我的代码

Thanks for help

感谢帮助

1 个解决方案

#1


0  

Have you registered the interceptor correctly in you module config?

您是否在模块配置中正确注册了拦截器?

If so, can you also modify your signin method to see if it is logging the response there? Change the code from

如果是这样,你还可以修改你的登录方法,看看它是否在那里记录响应?更改代码

signin: function (data, success, error) {
    $http.post(urls.BASE + '/auth/signin', data).then(function success(response, status, headers){

    })
}

to

signin: function (data, success, error) {
    $http.post(urls.BASE + '/auth/signin', data).then(function success(response)){
        console.log('Status:' + response.status);
        console.log('Response headers');
        console.dir(response.headers());
    })
}

When you use .then for $http.post, the response object contains these properties as per angular docs:

当您使用.then for $ http.post时,响应对象包含角度docs的这些属性:

data – {string|Object} – The response body transformed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.

#1


0  

Have you registered the interceptor correctly in you module config?

您是否在模块配置中正确注册了拦截器?

If so, can you also modify your signin method to see if it is logging the response there? Change the code from

如果是这样,你还可以修改你的登录方法,看看它是否在那里记录响应?更改代码

signin: function (data, success, error) {
    $http.post(urls.BASE + '/auth/signin', data).then(function success(response, status, headers){

    })
}

to

signin: function (data, success, error) {
    $http.post(urls.BASE + '/auth/signin', data).then(function success(response)){
        console.log('Status:' + response.status);
        console.log('Response headers');
        console.dir(response.headers());
    })
}

When you use .then for $http.post, the response object contains these properties as per angular docs:

当您使用.then for $ http.post时,响应对象包含角度docs的这些属性:

data – {string|Object} – The response body transformed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.