Node.js
[node.js] 서버에서 다른 웹사이트의 데이터를 가져와 응답하기
Stater
2018. 12. 28. 17:06
서버에서 다른 웹 사이트를 접속하여 데이터를 가져온 후 응답하는 과정이 필요 할 때 사용
이 경우에는 서버에서 HTTP 클라이언트 기능도 사용하게 됨
HTTP클라이언트가 GET과 POST 방식으로 다른 웹서버에 데이터를 요청 할 수 있다.
var http=require('http');
var options={
host:'www.google.com',
port:80,
path:'/'
};
var req=http.get(options,function(res){
//응답처리
var resData='';
res.on('data',function(chunck){
resData +=chunck;
});
res.on('end',function(){
console.log(resData);
});
});
req.on('error',function(err){
console.log("오류발생:"+err.message);
});
해당 소스는 do it node.js를 참조했습니다.
반응형