nodejs
// 引入 nodejs 的http核心模块 let querystring = require('querystring') let http = require('http') http .createServer(function (request, response) { console.log(`8000端口被访问`) response.setHeader('Access-Control-Allow-Origin', '*') // 允许所有的url 访问我的 // 返回数据 const resYes = { status: 200, msg: '成功登录', } const resNo = { status: 388, msg: '登录失败', } // 用户数据库 userInfo const userInfo = [ { name: 'zhulongxu', age: 25, gender: 'man', desc: 'script boy', secret: 123456, }, ] let url = request.url.substring(2) console.log(url) let arr = url.split('&') console.log(userInfo[0].name) function fn() { if (url.split('&')[0] === `username=${userInfo[0].name}`) { console.log(1234) response.write(JSON.stringify({ msg: '用户名已经注册' })) return } if (url.split('&')[0] === 'username=zhulx' && url.split('&')[1] === 'password=123') { response.write(JSON.stringify(resYes)) } else { s response.write(JSON.stringify(resNo)) } } fn() // 返回值 res username=&password= response.end() }) .listen(8000)