body-data
v1.0.7
Published
一个轻量、小巧的Node.js模块,用于检索 GET 或 POST 请求数据 | A lightweight, small Node.js module for retrieving GET or POST request data
Downloads
379
Readme
安装
npm install body-data --save
快速开始
// client
const script = document.createElement('script')
script.src = 'https://cdn.jsdelivr.net/npm/axios/dist/axios.js'
document.head.append(script)
const url = 'http://127.0.0.1:6870'
axios.get(url, { params: { name: 'Lete', age: 18 } })
axios.post(url, { name: 'Lete', age: 18 })
// server
const bodyData = require('body-data')
const http = require('http')
const server = http.createServer(async (req, res) => {
res.setHeader('Content-Type', 'application/json; charset:utf-8;')
const data = await bodyData(req)
res.end(JSON.stringify(data)) // output: { name: 'Lete', age: 18 }
})
server.listen(6870)