Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network error axios trying to get data from API #9

Open
MEADevloper opened this issue Jun 7, 2021 · 4 comments
Open

Network error axios trying to get data from API #9

MEADevloper opened this issue Jun 7, 2021 · 4 comments

Comments

@MEADevloper
Copy link

I always get a Network error when I try to get data from api using axios,

when i am using this api => https://jsonplaceholder.typicode.com/posts
i'ts work but when i use my api it doesn't work then

here is my code

import axios from 'axios'


let baseURL = ''

{
    Platform.OS == 'android'
    ? baseURL = 'http://10.0.2.2:3000/api/v1/' // android
    : baseURL =  'http://localhost:3000/api/v1/' // IOS

}

axios.get(`${baseURL}products`)
.then(res => {console.log(res) })
.catch(err => console.log(err)})






i'ts has error

Network Error
at http://packager.x5-xy3.anonymous.g-bazar.exp.direct/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:189790:25 in createError
at node_modules\axios\lib\adapters\xhr.js:91:24 in handleTimeout
at node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEvent
at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 in setReadyState
at node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 in __didCompleteResponse
at node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emit
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
at [native code]:null in callFunctionReturnFlushedQueue

@ubkhf8
Copy link

ubkhf8 commented Jul 3, 2021

Same Here getting api network error but when using locally it's working

@ubkhf8
Copy link

ubkhf8 commented Jul 8, 2021

did you find any solution?

@cjassu
Copy link

cjassu commented Sep 22, 2021

getting same error.

@Ali-Raza-400
Copy link

Ali-Raza-400 commented Aug 19, 2022

import { Platform } from 'react-native';

{
Platform.OS == 'android'
? (baseURL = 'http://192.168.51:3000/api/v1/')
: (baseURL = 'http://192.168.51:3000/api/v1/');
}

export default baseURL;

export const imageBaseUrl = 'http://192.168.51.:3000/';

Where the 192/168.51 is my ip address ....
You can put your own ip address by checking in terminal or CMD "ipconfig" where ipv4
@cjassu @ubkhf8 @MEADevloper

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants