0

I'm so tired to fix this problem i'ts work from https and it's do not work in http please help me

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

MEAbid
  • 560
  • 7
  • 11

1 Answers1

0

iOS sdk enforces connection to be in https protocol instead of http.you can add an exception to your domain inside info.plist file of the Xcode project.

Open your info.plist file of your project with any editor of your preference, then add this code at the end of the file before the last

<key>NSAppTransportSecurity</key>
<dict>
   <key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

check this link

Manojkanth
  • 1,071
  • 11
  • 27