2020/1/19 nodejs简单学习(关于GET/POST)

始作俑者 2020-01-19

const http = require(‘http‘)
const url = require(‘url‘)
const querystring = require(‘querystring‘)

http.createServer((require,response)=>{
  // GET请求
  let {pathname,query}=url.parse(require.url,true)
  console.log(pathname,query)

  // POST请求
  let result = []
  require.on(‘data‘, (buffer) => {
    result.push(buffer)
  })
  require.on(‘end‘, () => {
    let data = Buffer.concat(result).toString// toString是因为已知是接收帐号密码
    console.log(querystring.parse(data))
  })
}).listen(8080)

相关推荐