简体   繁体   English

apisauce 在 localhost 上出现网络错误

[英]apisauce gives network error on localhost

API Sauce is returning network error while testing API call from mobile on localhost API Sauce 在本地主机上测试来自移动设备的 API 调用时返回网络错误

I tested my API on POSTMAN TOOL its gives proper output.But it does not work in the app properly我在 POSTMAN TOOL 上测试了我的 API,它给出了正确的输出。但它不能在应用程序中正常工作

There's not enough information to tell exactly what the problem is.没有足够的信息来准确说明问题所在。 But I'll assume you're trying to consume your API from a different device/machine/emulator(?) and when you test with POSTMAN you actually test on the same one running the API, hence the apparently surprising results.但是我假设您正在尝试从不同的设备/机器/模拟器(?)使用您的 API,并且当您使用 POSTMAN 进行测试时,您实际上是在运行 API 的同一个设备上进行测试,因此结果显然令人惊讶。

In which case I would suggest you use the API machine IP instead of localhost .在这种情况下,我建议您使用 API 机器 IP 而不是localhost

example is, instead of doing例如,而不是做

const apiClient = create({
  baseURL: 'http://localhost:3000/api/v1',
  headers: {
    Accept: 'application/json',
  },
});

you rather do this你宁愿这样做

 const apiClient = create({
      baseURL: 'http://192.168.43.26:3000/api/v1',
      headers: {
        Accept: 'application/json',
      },
    });

Notice that now instead of using "localhost" we use the actual (hypothetical) ip of the machine running the API: "192.168.43.26".请注意,现在我们使用运行 API 的机器的实际(假设)ip:“192.168.43.26”,而不是使用“localhost”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 node.js 上的视频聊天应用程序与 webRTC(socket.io)在本地主机上工作正常,但在网络上出现错误 - video chat application on node.js with webRTC( socket.io) works fine on localhost but gives error on network socket.io和node.js在本地主机上给出错误 - socket.io and node.js gives error on localhost 为什么未将其保存在公用文件夹中,却在网络中出现404错误? - Why is this not being saved in public folder gives 404 error in Network? 使用 Netlify 启动 web 应用程序时使用 localhost 的网络错误 - Network error from using localhost when web app is launched with Netlify 本地主机无法在不同的网络上运行和运行? - Localhost not working and running on different network? Axios POST 请求在 React Native 中将图像添加到 FormData 结构时给出“网络错误” - Axios POST request gives a “Network Error” when adding image to FormData structure in React Native 该应用程序在本地主机上运行良好,但 Heroku 在尝试使用 post 登录或注册时出现错误的请求错误 - The app works fine with localhost but Heroku gives bad request error when trying to login or signup with post 错误:getaddrinfo ENOTFOUND本地主机 - Error: getaddrinfo ENOTFOUND localhost 本地主机上的CORS错误,这是正常现象吗? - CORS error on localhost, Is that a normal? Travis给我Redis与本地主机的连接:6379失败-连接ECONNREFUSED - Travis gives me Redis connection to localhost:6379 failed - connect ECONNREFUSED
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM