Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.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
Javascript 在JS中无法访问响应头_Javascript_Spring_Authentication_Redux_Axios - Fatal编程技术网

Javascript 在JS中无法访问响应头

Javascript 在JS中无法访问响应头,javascript,spring,authentication,redux,axios,Javascript,Spring,Authentication,Redux,Axios,我在前端使用React+Redux,后端使用Spring。在浏览器和postman中查看时,响应头包含授权头,但在尝试使用javascript访问时不包含授权头。我在网络选项卡和控制台选项卡上添加了显示响应标题的照片。我也在使用axios进行请求 auth.js ... export const authInit = (data) => { return dispatch => { dispatch(authInitStart()); ax

我在前端使用React+Redux,后端使用Spring。在浏览器和postman中查看时,响应头包含授权头,但在尝试使用javascript访问时不包含授权头。我在网络选项卡和控制台选项卡上添加了显示响应标题的照片。我也在使用axios进行请求

auth.js

...
export const authInit = (data) => {
    return dispatch => {
        dispatch(authInitStart());
        axios.post('/login', data)
            .then(response => {
                if(response.status === 200){

                    const param = {
                        'Authorization': response.headers.Authorization
                    };
                    console.log("Authorization----" + JSON.stringify(response));
                    console.log("Param----" + JSON.stringify(param));
                    localStorage.setItem('Authorization', param['Authorization']);
                    dispatch(authInitSuccess(param['Authorization']));

                }else{
                    dispatch(authInitFail('Request failed'));
                }
            }).catch(err => {
                dispatch(authInitFail('Network error'));
            });

    };
};
...
参数对象在此为空


有什么问题吗?

这能回答您的问题吗?若您使用的是JSP,那个么您可能正在从JSP变量读取头值。在某些情况下,JSP变量甚至在设置头之前就读取它的值。感谢您的响应@phuzi,但它没有帮助。感谢您的响应@shubham。这没用。