2017-09-24 5 views
0

로컬 httpd 모듈에서 실행중인 etcd 인스턴스에 het 요청을 보내려고합니다.오류 : getaddrinfo ENOTFOUND가 localhost, Nodejs에 요청을 생성하는 중임

같은 코드 모양이

'use strict'; 
const express = require('express'); 
const app = express(); 
var http = require('http'); 

const port = 10111; 

var encoded_url = encodeURI('/v2/keys/message -X GET'); 

var options = { 
    host: 'http://127.0.0.1:2379', 
    path: encoded_url 
}; 

var callback = function (response) { 
    var str = ''; 

    //another chunk of data has been recieved, so append it to `str` 
    response.on('data', function (chunk) { 
    str += chunk; 
    }); 

    //the whole response has been recieved, so we just print it out here 
    response.on('end', function() { 
    console.log(str); 
    }); 
} 

http.request(options, callback).end(); 

app.listen(port,() => { 
    console.log("server started on port " + port); 
}); 

하지만 난 결과를 얻을 터미널에서 같은 컬 요청을하면 나는 다음과 같은 오류

Error: getaddrinfo ENOTFOUND http://127.0.0.1:2379 http://127.0.0.1:2379:80 
    at errnoException (dns.js:28:10) 
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26) 

을 얻고있다

http://127.0.0.1:2379/v2/keys/message -X GET

무엇인지 파악할 수 없습니다. 문제.

답변

1

기본적으로 http.request()80 포트를 사용합니다.

사용이 대신 :

var options = { 
    protocol: 'http:', 
    host: '127.0.0.1', 
    port: 2379, 
    path: encoded_url 
};