一使用http对象的request方法,马上就看到控制台报错
node:events:304 throw er; // Unhandled 'error' event ^
或者整个事情:
node:events:304
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:8080
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1129:16)
at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:129:14)
Emitted 'error' event on ClientRequest instance at:
at Socket.socketErrorListener (node:_http_client:478:9)
at Socket.emit (node:events:327:20)
at emitErrorNT (node:internal/streams/destroy:194:8)
at emitErrorCloseNT (node:internal/streams/destroy:159:3)
at processTicksAndRejections (node:internal/process/task_queues:80:21) {
errno: -4078,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 8080
}
Process finished with exit code 1
http.request 只是不适用于不同的示例,它每次都会陷入此错误!这是什么废话?让我们从一本书中举一个例子:
const http = require('http');
const options = {
hostname: 'localhost',
port: '8080',
path: '/hello.html'
};
function getResponse(response) {
let data = '';
response.on('data', chunk => {
data += chunk;
});
response.on('end', () => console.log(data));
}
http.request(options, response => {
getResponse(response);
}).end();
它飞在那里。和其他人一样。其他一切都有效,但 http.request 无效。为什么他总是崩溃?
win 10,noda 最新,尝试更改端口
好吧,服务器是谁将提高 Vasya