2010-04-13 4 views

답변

7

기본적으로 http.Server 클래스의 Node.js는 any http method을 허용합니다.
request.method (api link)을 사용하여 방법을 가져올 수 있습니다.

예 :

var sys = require('sys'), 
    http = require('http'); 

http.createServer(function (request, response) { 
    response.writeHead(200, {'Content-Type': 'text/plain'}); 
    response.write(request.method); 
    response.end(); 
}).listen(8000); 

sys.puts('Server running at http://127.0.0.1:8000/'); 

이 요청에 사용 된 방법을 메아리 포트 8000에 대한 간단한 HTTP 서버를 생성한다.

POST을 얻으려면 request.method의 "POST"문자열을 확인하십시오. response.end에 대한


업데이트 : 버전 0.1.90 이후

, 응답을 종료하는 기능은 response.end 대신 response.close입니다. 이름 변경 외에도 end은이 데이터가 닫힌 것과 달리 보내지면 데이터를 보내고 응답을 닫을 수 있습니다. (api example)

+1

감사합니다. Maushu. 하나의 수정, 그것은 "response.close();" 대신에 "response.end();"... – intellidiot

+3

0.1.90부터'response.end()', IIRC –

관련 문제