且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ReactNative 端口 8081 问题:403 Forbidden

更新时间:2022-12-07 23:27:05

我搜索了很多,终于找到了如何在不同的端口上运行这个项目.如果您安装了任何防病毒软件,那么在开发时禁用防火墙或通过设置手动允许连接可能会有所帮助.

I searched around a lot and finally figured out how to run this project on a different port. If you have any Antivirus software installed then it may help if you disable the firewall while developing or allow connections manually through settings.

  1. 在不同的端口上启动 ReactNative

  1. Start ReactNative on a different port

react-native start --port 9080

这将打开一个新的命令提示符并在端口 9080 上启动 Metro bundler(您可以使用任何其他您想要的端口).等待依赖图完全加载.

This will open a new command prompt and start the metro bundler on port 9080 (you can use any other port you want). Wait for the dependency graph to be fully loaded.

现在在不同的命令提示符(项目目录)中使用以下命令在设备上构建和安装应用

Now in a different command prompt (project directory) use the below command to build and install the app on device

react-native run-android

现在在设备上加载应用程序后,您将看到 403 错误和红色屏幕.要使设备在不同的端口上通信,请使用以下命令.

Now once the app is loaded on device you will see the 403 error along with the red screen. To make the device communicate on a different port use below command.

adb 反向 tcp:8081 tcp:9080

adb reverse tcp:8081 tcp:9080

或者如果您连接了多个设备,请提供设备 ID(例如 FA6AA0301277)

or if you have multiple device connected then provide the device id (e.g. FA6AA0301277)

adb -s FA6AA0301277 reverse tcp:8081 tcp:9080

要了解连接的设备列表,请使用以下命令

To know the list of devices connected use below command

adb devices

就是这样,现在您应该可以看到索引页了 :)快乐编码:)

That's it, now you should be able to see the index page :) Happy Coding :)