Node.js GET/POST 要求
取得GET請求內容
案例:get.js
[code]var http = require('http'); var url = require('url'); var util = require('util'); http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type' : 'text/plain'}); res.end(util.inspect(url.parse(req.url, true))); }).listen(8888);
終端:
w3cschool.cc
取得POST請求內容
案例:post.js
[code]var http = require('http'); var querystring = require('querystring'); var util = require('util'); http.createServer(function (req, res) { // post 发送的数据 var post = 'username=zhang&age=23'; req.on('data', function (chunk) { post += chunk; }); req.on('end', function () { post = querystring.parse(post); console.log(post); res.end(util.inspect(post)); }) }).listen(8888);
以上是Node.js GET/POST請求的內容,更多相關內容請關注PHP網(www.php.A) !