我正在尝试调用"https";来自Expo React Native应用程序的localhost服务器。但我得到了";网络错误";。如何在React Native中调用https服务器?
在React Native中初始化baseUrl=>baseUrl = Platform.OS === "ios" ? "https://localhost:1999" : "https://10.0.2.2:1999"
如果你在pc上开发应用程序,并试图在手机上查看应用程序,你不应该使用"localhost";而是
连接到同一局域网,热点
如果在窗口上-
- 转到cmd
- 类型";ipconfig">
- 转到ipv4地址,它看起来像("192.168.178.43"(
- 这是在mobile中代替localhost编写的
- 将:放在后面并写入端口号
- 您的url将看起来像192.168.178.43:1999
如果在linux/mac上--去狂欢/钓鱼/zsh-类型";ifconfig";-与linux 中的操作相同
正如Durgesh Maurya在上面提到的那样。应该使用计算机的IP地址而不是localhost/10.0…记住在JS或TS中也要使用正确的协议。其次,你必须将你的CA添加到你的Android项目中,并遵循Android文档中列出的步骤
请确保将CA证书命名为my_CANOT to在原始文件夹中创建一个名为my_CA的目录。
如果我正确理解您的问题,请尝试键入
npm start
在您的终端。然后,它会提示您选择在模拟器中或在网络上运行它。你所要做的就是在键盘上敲"w"。它应该在默认浏览器中运行。
Starting Metro Bundler
› Metro waiting on [ip]
› Linking is disabled because the client scheme cannot be resolved.
› Press a │ open Android
› Press i │ open iOS simulator
› Press w │ open web
› Press r │ reload app
› Press m │ toggle menu
› Press d │ show developer tools
› shift+d │ toggle auto opening developer tools on startup (disabled)
› Press ? │ show all commands
只需在此控制台消息后点击"w">