React-Native:iOS 上 Axios 的问题 [英] React-Native: Problems with Axios on iOS

查看:113
本文介绍了React-Native:iOS 上 Axios 的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ReactNative 在 iOS 上的每个 Axios 请求上不断收到网络错误.

I'm using ReactNative keep getting a network error on every Axios Request on iOS.

Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:81)
    at XMLHttpRequest.dispatchEvent (event-target-shim.js:818)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:574)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:388)
    at XMLHttpRequest.js:501
    at RCTDeviceEventEmitter.emit (EventEmitter.js:189)
    at MessageQueue.__callFunction (MessageQueue.js:436)
    at MessageQueue.js:111
    at MessageQueue.__guard (MessageQueue.js:384)

显然,iOS 不允许不使用 HTTPS 的 API 运行,但根据我的研究,更新 Info.plist 应该可以解决问题.这是我更新它的方式:

Apparently, iOS doesn't allow APIs that don't use HTTPS to run, but as per my research, updating Info.plist should have done the trick. Here's how I have updated it:

此应用程序的 android 版本运行良好.有什么建议吗?

The android version of this application works perfectly fine. Any suggestions?

推荐答案

问题很简单.我的服务器托管在 localhost 上,您需要使用不是 127.0.0.1/localhost 的 IP/主机名.找到您的私有 IP 地址并在该地址上启动您的服务器,并在 react-native 中引用该地址.但是,127.0.0.1/localhost 在 Android 上运行良好.

The problem was pretty simple. My server is hosted on localhost, and you need to use an IP/hostname that is not 127.0.0.1/localhost. Find your private IP address and start your server on that and reference that in react-native. However, 127.0.0.1/localhost works fine on Android.

只要您使用 HTTPS 或允许忽略 iOS 项目工作区中可用的 Info.plist 文件中的 HTTPS,实时服务器也应该可以工作.

A live server should work too as long as you use HTTPS or allow ignoring HTTPS in your Info.plist file available in your iOS project workspace.

这篇关于React-Native:iOS 上 Axios 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆