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);
终端:
客户端:http://localhost:8888/user?name=w3c&email=w3c@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.cn)!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号