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

Node.js中http.request()请求本地Servez服务器返回408超时且无报错的问题求助

Node.js中http.request()请求本地Servez服务器返回408超时且无报错的问题求助

各位大佬求助!我在使用Node.js的http.request()请求本地运行在localhost:8080的Servez服务器时遇到了棘手的问题,折腾好久都没搞定,实在懵了来问问大家。

我在不同电脑上测试了同样的代码,没有任何报错信息,但每次都会返回HTTP响应码408(超时)。我完全是按照官方文档的写法来写的代码,实在搞不懂为什么会出现这种情况,如果是我哪里写错了,麻烦大家帮我指出需要修改的地方——我上网搜了一圈,也没找到相关的解决方案。

备注:Servez确实在localhost:8080正常运行着,是有可连接的服务器的

以下是我的代码:

const http = require('http');

ops = {
    hostname: 'localhost',
    port: '8080',
    path: '/',
    method: 'GET'
}

http.request(ops, res => {
    console.log('code: ' + res.statusCode + '\n');
    dat = '';

    res.on('data', chunk => {
        dat += chunk;
    }) 
    res.on('end', () => {
        console.log(dat);
    })
})

备注:内容来源于stack exchange,提问作者marcthird

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 13:18:03