[node.js] POST 방식 데이터 송수신

박우현·2021년 1월 5일
0
post-thumbnail

👌 POST 방식

POST 방식으로 데이터를 송수신하는 방법을 알아본다.

✔ 데이터 송신

  • form 태그의 속성값 중 하나인 method를 사용하면 form의 데이터를 post 방식으로 송신할 수 있다.
<form action="/create_process" method="post">
  <input type="text" name="title">
  <textarea name="description"></textarea>
  <input type="submit">
</form>

✔ 데이터 수신

  • pathname === '/create_process'로 분기한 후, request.on을 이용해 데이터를 받아온다
...
else if(pathname === '/create_process'){
  var body = '';
  request.on('data', function(data){
    body = body + data;
  });
  request.on('end', function(){
    var post = qs.parse(body);
    var title = post.title;
    var description = post.description
    });
  ...
}
...

👍 참고 사이트

0개의 댓글