前端学习(1312):响应报文
生活随笔
收集整理的這篇文章主要介紹了
前端学习(1312):响应报文
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?
//創(chuàng)建網(wǎng)站服務(wù)器模板 const http = require('http'); //網(wǎng)站服務(wù)器對象 const app = http.createServer(); //客戶端有請求 app.on('request', (req, res) => {//獲取請求方式//console.log(req.method);//獲取請求地址//console.log(req.url);//響應(yīng)報文res.writeHead(200, {'content-type': 'text/html;charset=utf8'});if (req.url == '/index' || req.url == '/') {res.end('<h2>welcome to index</h2>')} 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('服務(wù)器啟動成功');運行結(jié)果
總結(jié)
以上是生活随笔為你收集整理的前端学习(1312):响应报文的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 雷达波段划分
- 下一篇: 前端学习(1332):mongodb安装