如何处理理客户端get/post请求
- url.parse(urlString[, parseQueryString[, slashesDenoteHost]])
- urlString url字符串串
- parseQueryString 是否解析
- slashesDenoteHost
- 默认为false,//foo/bar 形式的字符串串将被解释成 { pathname: ‘//foo/bar’ }
- 如果设置成true,//foo/bar 形式的字符串串将被解释成 { host: ‘foo’, pathname: ‘/bar’ }
console.log(url.parse('https://api.xdclass.net/pub/api/v1/web/product/find
_list_by_type?type=2',true,true))
- get请求⽤用于客户端向服务端获取数据,post请求是客户端传递数据给服务端
- 处理理get请求
const url = require('url');
const http = require('http');
//
console.log(url.parse('https://api.xdclass.net/pub/api/v1/web/product/find
_list_by_type?type=2',true,true))
const server = http.createServer((req,res) => {
let urlObj = url.parse(req.url,true);
res.end(JSON.stringify(urlObj.query))
})
server.listen(3000,()=>{
console.log('监听3000端⼝口')
})
const url = require('url');
const http = require('http');
//
console.log(url.parse('https://api.xdclass.net/pub/api/v1/web/product/find
_list_by_type?type=2',t