You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求协助排查Axios网络错误:Chat模块获取联系人失败

问题描述
  • 获取联系人失败,报错信息:

Error fetching contacts:, [AxiosError: Network Error]
at .expo\screens\Chat.js:null in fetchData
at node_modules@babel\runtime\helpers\asyncToGenerator.js:null in asyncGeneratorStep
at node_modules@babel\runtime\helpers\asyncToGenerator.js:null in Promise$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in queueReactNativeMicrotask
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callTimer
... 8 more stack frames from framework internals

  • API路由http://192.168.0.126:8082可正常获取信息,但Chat模块调用异常
  • Postman中用HTTPS请求该路由返回cannot get
解决方案
  • 修正请求协议
    你的API使用HTTP协议,Postman用HTTPS请求失败说明Chat模块可能误用了HTTPS协议。打开.expo/screens/Chat.js的fetchData函数,确认请求URL前缀是http://而非https://。

  • 排查网络连通性

    • 确认运行Expo的设备和API服务器在同一局域网,测试设备能否ping通192.168.0.126
    • 检查API服务器防火墙设置,确保8082端口对外开放
    • iOS模拟器可尝试将地址替换为localhost;Android模拟器替换为10.0.2.2(映射本地主机)
  • 细化Axios错误排查
    在fetchData中添加错误详情打印,定位具体问题:

    try {
      const response = await axios.get('http://192.168.0.126:8082/your-contacts-endpoint');
      // 处理响应逻辑
    } catch (error) {
      console.error('完整错误:', error);
      console.error('错误代码:', error.code);
      console.error('响应数据:', error.response?.data);
    }
    
  • 检查API端点路径
    确认Chat模块调用的是正确的联系人接口路径(比如/api/contacts),Postman请求时需带上完整路径,仅请求根地址可能返回404导致cannot get。

内容的提问来源于stack exchange,提问作者Jun

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 13:29:56