【问题标题】:Getting no data with express/react/next.js data request using http使用 http 获取 express/react/next.js 数据请求没有数据
【发布时间】:2019-02-03 01:07:03
【问题描述】:

问题:

我正在尝试使用 http 从 http://localhost:3000/auth/sendUserData 请求数据,但我没有收到任何数据/响应(没有 console.logs)。

我正在使用什么:

Next.js/React、Node(后端服务器)、getInitialProps (Next.js)。

代码:

用户数据.js

const http = require("http");
const Userdata = {};

Userdata.getUserData = async function(){
    let url = `http://${process.env.HOST}:${process.env.PORT}/auth/sendUserData`
    console.log(url);
    const options = {
        host: process.env.HOST,
        port: process.env.PORT,
        path: '/auth/sendUserData'
    };

    http.get(options, function(res) {
        console.log("Got response: " + res.statusCode);

        res.on("data", function(chunk) {
            console.log("BODY: " + chunk);
        });

    }).on('error', function(e) {
        console.log("Got error: " + e.message);
    });
};

export default Userdata;

http://localhost:3000/auth/sendUserData

{
_id: "5c5521f823a5d183945fd62f",
name: "Saddy",
steamID: "76561198151478478",
__v: 0
}

【问题讨论】:

    标签: javascript node.js reactjs http next.js


    【解决方案1】:

    问题在于后端身份验证,因为它是在服务器上而不是在客户端上呈现的,导致会话丢失

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-03
      • 2023-04-10
      相关资源
      最近更新 更多