【问题标题】:Axios (React Native) POST request working on iOS (emulator) but not on Android (emulator)Axios (React Native) POST 请求适用于 iOS(模拟器)但不适用于 Android(模拟器)
【发布时间】:2020-04-10 05:15:12
【问题描述】:

请帮帮我,我很纠结这个问题: 我在 React Native 上使用 Axios 发出异步请求,该请求仅在 iOS 模拟器中正常工作,但不适用于 Android 模拟器(403 禁止响应)。

我正在做的请求是:

const signIn = dispatch => async ({ email, password }) => {
try {
    const response = await authApi.post('/login', ({ email, password }));
} catch (err) {
    console.error(err);
}};

authApi 在哪里:

import axios from 'axios';

export default axios.create({
    baseURL: 'https://dev.lyribooks.com/api/api/auth',
    withCredentials: true,
    crossdomain: true,
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    }
});

【问题讨论】:

  • 您是否在Android设备反应原生上下文菜单中激活了调试js选项?

标签: javascript react-native async-await axios expo


【解决方案1】:

@Oleg 非常感谢您的建议。可能是错误的服务器配置阻止了我的请求,因为在我将用户代理添加到白名单后,它现在一切正常。

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 2023-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多