反应本机 axios 请求在 IOS 模拟器中不起作用

Ari*_*rif 5 ios ios-simulator react-native axios

我正在尝试使用axios从 API 获取数据。

这是我发出 get 请求的代码:

export const loadBloodGroups = () => {
    return (dispatch) => {

        dispatch({ type: LOADING_BLOOD });

        const url = `http://www.example.org/api/bloodgroup/getusersbloodgroup`;
        axios.get(url)
        .then(response => loadingSuccess(dispatch, response))
        .catch(error => loadingFail(dispatch, error));
    };
};

const loadingFail = (dispatch, error) => {
    console.log(error);
    dispatch({ 
        type: LOADING_BLOOD_FAIL,
        payload: error
    });
};

const loadingSuccess = (dispatch, response) => {
    dispatch({
        type: LOADING_BLOOD_SUCCESS, 
        payload: response
    });
}; 
Run Code Online (Sandbox Code Playgroud)

http 的 info.plist 设置:

在此输入图像描述

在android模拟器上可以正常使用,但在IOS模拟器上就不行。

在我的浏览器调试控制台中它显示:

在此输入图像描述

Mac 终端显示:

在此输入图像描述

谁能告诉我,我哪里出错了?或者我需要为IOS做任何其他配置吗?

我的平台:

  • 操作系统:Mac 10.13
  • 节点:10.7
  • npm:6.3.0
  • 反应:16.4.1
  • 反应本机:0.55

小智 1

使用以下命令更新您的 Info.plist:

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
Run Code Online (Sandbox Code Playgroud)