React Redux-401-未经授权-请求标头中缺少标头

时间:2018-12-27 05:34:45

标签: javascript reactjs react-native redux react-redux

我在React Redux投掷401时遇到问题-未经授权的错误。

我正在尝试获取带有授权标头的服务API数据,但得到401-未经授权的错误,并且响应是缺少请求标头。

我在操作中包括了“标头”部分,并为jContent令牌提供了“ Content-Type”和“ Authorization”。

我不确定我缺少什么。

有人可以帮我解决这个问题吗?

这是我的操作代码:

export const getItem = () => {
  return (dispatch, getState) => {
    debugger;
    dispatch({
      type: 'API_REQUEST',
      options: {
        method: 'GET',
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
          'Authorization': 'jwt eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjIxZjE0M2U3LTlhMzEtNGIwNi1hMzJhLTY0NDM2NTFiMTUxZSIsImRhdGUiOiJ5eXl5LTM3LVdlOjExOjM3OjE3IiwiaWF0IjoxNTQzNDA1MDM3fQ.G0h1kh5sunxpKNcFdb5s54c0hKiXyPJhRywbR5-_sk0'
        },
        endpoint: `http://18.222.137.195:3000/v1/item?offset=0`,
        actionTypes: {
          success: types.GET_ITEM_SUCCESS,
          loading: types.GET_ITEM_LOADING,
          error: types.GET_ITEM_ERROR
        }
      }
    });
  };
};

这是我的Reducer代码:

import * as types from '../actions/registerItemTypes';

export const initialState = {
  getItem: {}
};

const registerItem = (state = initialState, action) => {
  switch (action.type) {


    case types.GET_ITEM_LOADING:
      return { ...state, loading: true, data: null };

    case types.GET_ITEM_SUCCESS:
      return { ...state, loading: false, getItem: action.data};

    case types.GET_ITEM_ERROR:
      return { ...state, loading: false, error: action.data};

    default: {
      return state;
    }
  }
}

export default registerItem;

0 个答案:

没有答案
相关问题