博客
关于我
用postman测试url参数
阅读量:319 次
发布时间:2019-03-04

本文共 658 字,大约阅读时间需要 2 分钟。

const http = require('http');const querystring = require('querystring');http.createServer((req,res)=>{    if(req.url.startsWith('/login')){        let pdata = '';        req.on('data',(chunk)=>{            pdata += chunk;        });        req.on('end',()=>'{            let obj = querystring.parse(pdata);            res.end(obj.id+' ---- '+obj.name);        })    }}).listen(3000,()=>'{        console.log('server is on!');    });

这是一个Node.js服务器代码示例,用于处理登录请求。服务器创建了一个HTTP服务器,并监听3000端口。当收到以'/login'开头的请求时,服务器会读取请求数据,并使用querystring.parse解析参数。最后,服务器将解析后的id和name返回给客户端。

在Postman测试时,需要选择"Content-Type": "application/x-www-form-urlencoded"作为请求头,这样可以确保数据被正确解析并返回。

转载地址:http://ontq.baihongyu.com/

你可能感兴趣的文章
PostGIS中获取所有EPSG的编码以及对应Proj4字符串
查看>>
SpringBoot中集成海康威视SDK实现布防报警数据上传/交通违章图片上传并在linux上部署(附示例代码资源)
查看>>
PostGIS在Windows上的下载与安装
查看>>
Qt开发——网络编程之UDP客户端
查看>>
postgis数据库优化_postgresql 性能优化
查看>>
postgis求面积、交集等相关函数
查看>>
postgis相关函数
查看>>
Postgres Docker版本安装mysql_fdw 插件
查看>>
Postgres invalid command \N数据恢复处理
查看>>
Postgres like 模糊查询匹配集合
查看>>
Postgres 自定义函数内实现 in 操作符的递归查询
查看>>
Postgres 返回当前时间前后指定天数的集合
查看>>
postgres--vacuum
查看>>
postgres--wal
查看>>