本文介绍了ReactNative 端口 8081 问题:403 Forbidden的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 上使用 ReactNative 进行开发时,我遇到了低于 403 的错误.这是因为 ReactNative 默认使用的端口 8081 正在被另一个程序使用.就我而言,它是迈克菲(感谢迈克菲让这更难).

While developing using ReactNative on Windows, I am getting below 403 error. This is because port 8081 which ReactNative uses by default is being used by another program. In my case it was McAfee (Thanks McAfee for making this harder).

运行项目的命令:react-native run-android

推荐答案

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

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

这篇关于ReactNative 端口 8081 问题:403 Forbidden的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:05