You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React+Node.js注册/登录遇Network request failed及404错误求助

React前端+Node.js后端注册/登录网络错误问题

用React开发前端应用、Node.js搭建后端,注册或登录时持续遭遇相同的网络错误TypeError: Network request failed。Postman测试完全正常,说明后端、数据库及前端传值逻辑无问题,但浏览器提示:

"register:1 Failed to load resource: the server responded with a status of 404 (Not Found)"

SignUpScreen.js

function SignUpScreen(props) {

    const navigation = useNavigation();

    const navigateToSignIn = () => {
        navigation.navigate('Sign In');
      };

        const handleRegister = async () => {
            console.log('Start handleRegister');
            try {
                const response = await fetch('http://localhost/register', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({  Email, password }),
                });

                console.log('After fetch'); 

                const data = await response.json();
        };

Backend code

app.post('/register', async (req, res) => {
    try {
        const { email, password } = req.body;
        
        const saltRounds = 10;
        const hashedPassword = await bcrypt.hash(password, saltRounds);


        const user = { email, password: hashedPassword };
        const insertUserQuery = 'INSERT INTO users (email, password) VALUES (?, ?)';

});

已尝试以下方案但未解决:

  • 将“localhost”替换为IP地址
  • 使用CORS
  • 在Android清单文件android/app/src/main/AndroidManifest.xml中添加android:usesCleartextTraffic="true"
  • 更换不同物理设备

内容的提问来源于stack exchange,提问作者steez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 02:22:17