前端学习(1313):get请求参数
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1313):get请求参数
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
//創(chuàng)建網(wǎng)站服務(wù)器模板
const http = require('http');
//內(nèi)置模塊
const url = require('url');
//網(wǎng)站服務(wù)器對象
const app = http.createServer();
//客戶端有請求
app.on('request', (req, res) => {//獲取請求方式//console.log(req.method);//獲取請求地址//console.log(req.url);//響應(yīng)報(bào)文res.writeHead(200, {'content-type': 'text/html;charset=utf8'});// console.log(req.url);//console.log(url.parse(req.url, true));let { query, pathname } = url.parse(req.url, true);console.log(query.name);console.log(query.age);if (pathname == '/index' || req.url == '/') {res.end('<h2>welcome to index</h2>')} else if (pathname == '/list') {res.end('welcome to list')} else {res.end('not found');}if (req.method == 'POST') {res.end('post')} else if (req.method == 'get') {res.end('get')}//res.end('<h2>hello user</h2>')
});
//監(jiān)聽端口
app.listen(3000);
console.log('服務(wù)器啟動(dòng)成功');
運(yùn)行結(jié)果
總結(jié)
以上是生活随笔為你收集整理的前端学习(1313):get请求参数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端学习(1115):call appl
- 下一篇: VWware15安装windows XP