【问题标题】:Error when sending https request to ROBLOX API向 ROBLOX API 发送 https 请求时出错
【发布时间】:2021-07-31 05:58:42
【问题描述】:

我正在向 Roblox 编写一个简单的 API 请求,以便检索 X-CSRF-TOKEN 来执行 POST 请求。我面临的问题是“错误:套接字挂起”。

我试图在浏览器中运行该链接,它会显示一个 JSON 表,但是当我通过 node.js 发出请求时,它会出错。

const https = require("https")

const options = {
    hostname: "groups.roblox.com",
    path: "/v1/groups/5307563",
    method: "GET",
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Cookie': '.ROBLOSECURITY=' + cookie
    }
}

const request = https.request(options, res => {
    
    res.on('data', data => {
       console.log("data received")
    })

});

request.on('error', error => {
    console.log(error)
})

【问题讨论】:

标签: node.js roblox


【解决方案1】:

您需要以request.end() 结束请求。


const https = require("https")

const options = {
    hostname: "groups.roblox.com",
    path: "/v1/groups/5307563",
    method: "GET",
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Cookie': '.ROBLOSECURITY=' + cookie
    }
}

const request = https.request(options, res => {
    
    res.on('data', data => {
       console.log("data received")
    })

});

request.on('error', error => {
    console.log(error)
})
request.end()

【讨论】:

    猜你喜欢
    • 2020-07-01
    • 2021-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 2019-08-08
    • 2018-11-25
    相关资源
    最近更新 更多