1. HTTP(hypertext transport protocol) 协议 【超文本传输协议】
  2. 协议详细规定了浏览器和万维网服务器之间互相通信的规则

2-1 请求报文

  1. 重点是格式与参数
  2. 请求
  3. 1、行 POST /s?ie = utf-8 HTTP/1.1
  4. 2、头 Host: xxx.com
  5. Cookie:name=xxx
  6. Content-type:application/x-www-form-urlencoded
  7. User-Agent:chrome 83
  8. 3、空行
  9. 4、体 uesrname=admin&password=admin

image.png

2-1 响应报文

  1. 1、行 HTTP/1.1 200 OK
  2. 2、头 Content-type:text/html;charset=utf-8
  3. Content-length:2048
  4. Content-encoding:gzip
  5. 3、空行
  6. 4、体 <html>
  7. <head>
  8. </head>
  9. <body>
  10. </body>
  11. </html>

image.png
image.png

2-3 express基本使用

  1. 安装node.js
  2. 1、在vscode中打开终端
  3. 2、输入 npm init --yes
  4. 3、安装express框架 npm i express
  5. 4、打开js文件 按照步骤使用框架
  6. 5、将js文件在终端打开 输入 node express基本使用.js
  1. //1、引入express
  2. const express = require('express')
  3. //2、创建应用对象
  4. const app = express()
  5. //3、创建路由规则
  6. //request是对请求报文的封装
  7. //response是对响应报文的封装
  8. app.get('/',(request,response)=>{
  9. //设置响应
  10. response.send('hello express')
  11. })
  12. //4、监听端口启动服务
  13. app.listen(8000,()=>{
  14. console.log("服务已经启动,8000端口监听中...")
  15. })

8000端口
image.pngimage.png
image.png