node.js request and response related
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了node.js request and response related相关的知识,希望对你有一定的参考价值。
一 取值 post 和get取值
1)
GET /test?name=fred&tel=0926xxx572
app.get(‘/test‘, function(req, res) {
console.log(req.query.name);
console.log(req.query.tel);
});
2)POST
<form action=‘/test‘ method=‘post‘>
<input type=‘text‘ name=‘name‘ value=‘fred‘>
<input type=‘text‘ name=‘tel‘ value=‘0926xxx572‘>
<input type=‘submit‘ value=‘Submit‘>
</form>
app.post(‘/test‘, function(req, res) {
console.log(req.query.id);
console.log(req.body.name);
console.log(req.body.tel);
});
3) HTTP Routing :
GET /hello/fred/0926xxx572
app.get(‘/hello/:name/:tel‘, function(req, res) {
console.log(req.params.name);
console.log(req.params.tel);
});
参考:
https://cnodejs.org/topic/50a333d7637ffa4155c62ddb
以上是关于node.js request and response related的主要内容,如果未能解决你的问题,请参考以下文章
Node.js - Socket.io:socket.request 未定义
Node.js 中的 SPDY https.request()
Request —— 让 Node.js http请求变得超简单
Node.js知识学习之——Node.js and MongoDB – Getting started with MongoJS