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