我是在回家的路上发布的,所以请原谅缺少代码,但我会尽力尽可能详细,并在今晚尽可能添加代码。所以本质上我有一个使用 redux 和 axios 的 React Native 应用程序。简短的回顾(遵循的代码)可能会解释我做错了什么。
\n\n服务api.js \n使用基本 url 创建并导出基本 axios。
\n\nconst ServiceApi = axios.create({\n baseURL: BASE_URL,\n responseType: \'json\'\n});\nRun Code Online (Sandbox Code Playgroud)\n\nAuthReducer.js \n登录时使用 post 方法手动设置授权标头。这适用于 android 和 ios 登录返回,我使用授权标头。
\n\nreturn {\n type: PERFORM_LOGIN,\n payload: {\n user: {\n name: username\n },\n request: {\n url: \'/login\',\n method: \'post\',\n headers: { \n \'Authorization\': \'Basic \' + basicAuth\n }\n }\n }\nRun Code Online (Sandbox Code Playgroud)\n\n登录时,我返回以下 redux-axios 操作,您可以看到我设置了标题:手动授权,这效果很好。
\n\n // On login success, set the authInterceptor responsible for adding headers\n authInterceptor = ServiceApi.interceptors.request.use((config) …Run Code Online (Sandbox Code Playgroud)