ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 创建服务器 ~~~ var http = require('http') var server = http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}) res.end("hello Node!") }) server.listen(3000) ~~~ ### Request ~~~ var server = http.createServer(function (req, res) { //请求方式 var method = req.method //路由 var url = req.url //请求头 var header = req.headers console.log(method, url, header) //请求体 var body = [] req.on('data', function (chunk) { body.push(chunk) }).on('end', function () { body = Buffer.concat(body).toString() }) console.log(body) }) ~~~ ### Response ~~~ var http = require('http') var server = http.createServer(function (req, res) { //响应 res.writeHead(200, {'Content-Type': 'text/plain'}) res.write('Hello ') res.end("Node!") //结束请求 }) server.listen(3000) ~~~