Lesson 16

HTTP 协议

基本认知

版型

Request + Response

Request 格式

method + path + version
headers
body
样例
GET /hello/hey HTTP/1.1
Host: localhost:8080
cache-control: no-cache
POST /hello/hey HTTP/1.1
Host: localhost:8080
Content-Type: application/json
cache-control: no-cache

{
    "a": 1
}

Response 格式

version + status code + status message 
headers
body 
GET 200 OK 
Content-Type: application/json

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

URI

HTTP 服务器

功能

基本款

url

method

headers

query

fragment

body - form data

body - json

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifac`tId>
        <version>5.1.6.RELEASE</version>
    </dependency>
</dependencies>
<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

静态 HTTP 服务器Static HTTP Server

什么是

以 HTTP 传输协议,返回 一个服务器文件夹路径下的所有文件

基本功能

返回内容

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.1.6.RELEASE</version>
</dependency>

文件下载

Content-Type: text/html; charset=utf-8
Content-Disposition: attachment; filename="cool.html"

文件夹默认网页

index.html

异常处理

404 Not Found

ZZAX 微信公众

文档一更新,立刻告诉你