小编ken*_*son的帖子

React 本机 axios ios 未针对 apache/php 进行身份验证

我是在回家的路上发布的,所以请原谅缺少代码,但我会尽力尽可能详细,并在今晚尽可能添加代码。所以本质上我有一个使用 redux 和 axios 的 React Native 应用程序。简短的回顾(遵循的代码)可能会解释我做错了什么。

\n\n

服务api.js \n使用基本 url 创建并导出基本 axios。

\n\n
const ServiceApi = axios.create({\n    baseURL: BASE_URL,\n    responseType: \'json\'\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

AuthReducer.js \n登录时使用 post 方法手动设置授权标头。这适用于 android 和 ios 登录返回,我使用授权标头。

\n\n
return {\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    }\n
Run 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)

php apache zend-framework react-native axios

4
推荐指数
1
解决办法
2025
查看次数

标签 统计

apache ×1

axios ×1

php ×1

react-native ×1

zend-framework ×1