0
url '/ serverTest'에 대해 localhost : 8000에서 localhost : 5000으로 GET 요청을 보내려고합니다. 소켓 끊기 오류가 발생합니다. 이 문제를 어떻게 해결할 수 있습니까? (요청을 처리 할 서버) 포트 5000에node.js 로컬 서버 포트 5000에서 8000으로 http 요청한 경우 오류가 발생합니다.
는서버 :
var express = require("express"), http = require('http');
app.get('/serverTest', function(req, res){
//authenticate request
//send message
res.writeHead(200, {'Content-Type':'application/json'});
res.end(JSON.stringify({message:'hello'}));
});
app.listen(5000, function() {
console.log("Listening on " + port);
});
포트 8000 (요청을하게 서버)에 서버 :에서 호스팅 서버에서 얻은
var express = require("express"), http = require('http');
var port = 8000;
app.listen(port, function() {
console.log("Listening on " + port);
makeACall();
});
function makeACall(){
var options = {
host:'localhost',
port: 5000,
path: '/serverTest',
method: 'GET'
};
http.request(options, function(response) {
var str = '';
response.on('data', function (chunk) {
str += chunk;
});
response.on('end', function() {
console.log(str);
});
});
}
오류 포트 8000 :
events.js:72
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (http.js:1442:15)
at Socket.socketOnEnd [as onend] (http.js:1538:23)
at Socket.g (events.js:175:14)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:910:16
at process._tickCallback (node.js:415:13)