【问题标题】:Getting net::ERR_SSL_PROTOCOL_ERROR获取网络::ERR_SSL_PROTOCOL_ERROR
【发布时间】:2021-08-01 16:15:18
【问题描述】:

我正在尝试使用我在 nodejs 中使用护照模块制作的 REST api 进行简单的登录身份验证。 我的前端调用了这个函数,但是这个函数返回一个错误并且没有发生身份验证。帖子 fn 不起作用。

export const loginUser = (creds) => (dispatch) => {
    // We dispatch requestLogin to kickoff the call to the API
    dispatch(requestLogin(creds))

    return fetch(baseUrl + 'users/login', {
        method: 'POST',
        headers: { 
            'Content-Type':'application/json' 
        },
        body: JSON.stringify(creds)
    })
    .then(response => {
        console.log("HELLO");
        if (response.ok) {
            return response;
        } else {
            var error = new Error('Error ' + response.status + ': ' + response.statusText);
            error.response = response;
            throw error;
        }
        },
        error => {
            throw error;
        })
    .then(response => response.json())
    .then(response => {
        console.log("HELLO2");
        if (response.success) {
            // If login was successful, set the token in local storage
            localStorage.setItem('token', response.token);
            localStorage.setItem('creds', JSON.stringify(creds));
            console.log(response);
            // Dispatch the success action
            // dispatch(fetchFavorites());
            dispatch(receiveLogin(response));
        }
        else {
            var error = new Error('Error ' + response.status);
            error.response = response;
            throw error;
        }
    })
    .catch(error => dispatch(loginError(error.message)))
};

【问题讨论】:

    标签: javascript node.js reactjs rest redux


    【解决方案1】:

    所以,这背后的原因是我的应用程序同时托管静态文件和服务器。 因此,服务器使用 404 文件而不是 json 数据作为响应进行响应。 当我将客户端和服务器分开并将它们托管在不同的平台上时解决了。

    【讨论】:

      猜你喜欢
      • 2012-11-21
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 2012-07-12
      相关资源
      最近更新 更多