[英]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.