API Sauce is returning network error while testing API call from mobile on localhost
I tested my API on POSTMAN TOOL its gives proper output.But it does not work in the app properly
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.
In which case I would suggest you use the API machine IP instead of 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".
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.