callFunctionReturnFlushedQueue

callFunctionReturnFlushedQueue

本文介绍了网络错误 axios 试图从 API 获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我太累了,无法解决这个问题,我在 https 中无法使用,在 http 中无法使用,请帮助我

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

当我使用这个 api =>https://jsonplaceholder.typicode.com/posts我可以工作,但是当我使用我的 api 时它不起作用

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

这是我的代码

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)})

我有错误

网络错误在 http://packager.x5-xy3.anonymous.g-bazar.exp.direct/node_modules%5Cexpo%5CAppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:189790:25 在 createError 中在 node_modules\axios\lib\adapters\xhr.js:91:24 在 handleTimeout在 node_modules\event-target-shim\dist\event-target-shim.js:818:20 在 EventTarget.prototype.dispatchEvent在 node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 在 setReadyState在 node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 中的 didCompleteResponse在 node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 在发射在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in callFunction在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 inguard$argument_0在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 守卫在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 在 callFunctionReturnFlushedQueueat [native code]:null in callFunctionReturnFlushedQueue

Network Errorat 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 createErrorat node_modules\axios\lib\adapters\xhr.js:91:24 in handleTimeoutat node_modules\event-target-shim\dist\event-target-shim.js:818:20 in EventTarget.prototype.dispatchEventat node_modules\react-native\Libraries\Network\XMLHttpRequest.js:600:10 in setReadyStateat node_modules\react-native\Libraries\Network\XMLHttpRequest.js:395:6 in didCompleteResponseat node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:189:10 in emitat node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in callFunctionat node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in guard$argument_0at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in guardat node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueueat [native code]:null in callFunctionReturnFlushedQueue

推荐答案

iOS sdk 强制连接使用 https 协议而不是 http.您可以在 Xcode 项目的 info.plist 文件中向您的域添加例外.

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.

使用您喜欢的任何编辑器打开项目的 info.plist 文件,然后将此代码添加到文件末尾最后一个之前

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>

检查此链接

这篇关于网络错误 axios 试图从 API 获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 14:04