Basic introduction
One of the most important aspects of NODEJS is the ability to implement HTTP and HTTPS servers and services very quickly. HTTP services are fairly low-level, you may want to use different modules, such as Express, to implement the complete Web server, the HTTP module does not provide processing routes, cookies, caches and other calls. Our main use of HTTP modules is where the backend Web services are implemented for application use.
Code section
Main API:
Http://nodejs.cn/api/http.html
Example:
get/** * HTTP GET request * HTTP://192.168.31.162:9001?NAME=001&PWD=AAAAAA */function Creategetserver () {http. Createserver (function (req, res) {Res.writehead ($, {' Content-type ': ' Text/plain '}); Parse URL parameter console.log (req.url); var params = Url.parse (Req.url, true). Query; Res.write ("URL:" + req.url + "\ n"); Res.write ("Name:" + params.name + "\ n"); Res.write ("PWD:" + params.pwd); Res.end (); }). Listen (9001);} post/** * HTTP POST request * HTTP://192.168.31.162:9002?NAME=001&PWD=AAAAAA * psot:{"AAA": "001"} */function Createpostserver () {Http.createserver (function (req, res) {var params = Url.parse (Req.url, true). Query; var body = ""; Req.on (' Data ', function (chunk) {body + = chunk; Console.log (body); }); Req.on (' End ', function () {//parse parameter//BODY = Querystring.parse (body); Setting the response header information and encoding Res.writeheaD ($, {' Content-type ': ' Text/html; Charset=utf8 '}); Res.write (body); Res.end (); }); }). Listen (9002);}
Reference:
Http://nodejs.cn/api/http.html
node. JS Get/post Request
node. JS Web Module
Nodejs HTTP Service
Node/lib/_http_server.js
Node.js--http Source Code Interpretation
An analysis of Nodejs HTTP module
nodejs--creating the simplest HTTP server
Nodejs HTTP Network Module