前端学习(1311):请求报文
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1311):请求报文
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
//創(chuàng)建網(wǎng)站服務器模板
const http = require('http');
//網(wǎng)站服務器對象
const app = http.createServer();
//客戶端有請求
app.on('request', (req, res) => {//獲取請求方式//console.log(req.method);//獲取請求地址//console.log(req.url);if (req.url == '/index' || req.url == '/') {res.end('welcome to index')} else if (req.url == '/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('服務器啟動成功');
運行結果
總結
以上是生活随笔為你收集整理的前端学习(1311):请求报文的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 前端学习(1424):ajax低版本兼容
- 下一篇: 前端学习(813):dom简介