知识库 知识库
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)

Jim FuckPPT

Java小学生
首页
  • Hyperskill - Java

    • Java basic
    • Java OOP
    • 应知
    • 扩展
    • IO & Stream
    • Error & Exception
    • Algorithm & Data structure
    • Design pattern
    • Web
    • Spring boot
  • 练习题

    • 选择题 & 填空题
    • 代码题
  • Frank - Java与生活 (OOP)

    • 参考资料
    • Java基础
    • OOP上半部分
    • OOP下半部分
  • Frank - Java API进阶

    • Base API
    • Unit Test and main function
  • 学习笔记
  • 学习笔记

    • 数据库
  • Frank - MySQL删库跑路

    • 安装、连接、配置
    • 基本操作——数据库
    • 基本操作——表
    • 基本操作——数据
    • 数据类型
    • 列属性完整性
    • 数据库设计思维
    • 单表查询
    • 多表查询
  • 学习笔记

    • 其它
  • Frank - Linux现代方法

    • 必知
    • 命令
    • 技巧
  • 技术文档
  • Git
  • GitHub技巧
  • 前端
  • Khan Academy - 语法
  • Monthly
  • 阅读
  • Others
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
收藏
  • 标签
  • 归档
GitHub (opens new window)
  • Hyperskill - Java

    • Java basic

    • Java OOP

    • 应知

    • 扩展

    • IO & Stream

    • Error & Exception

    • Algorithm & Data structure

    • Design pattern

    • Web

      • Theory:World Wide Web
      • Theory:HTTP
      • Theory:HTTP URL
      • Theory:HTTP messages
        • The format of messages
        • The simplified HTTP interaction
        • Methods
        • Status codes
        • Conclusion
      • Theory:MVC
      • Theory:Introduction to Spring Web MVC
      • Theory:REST
      • Theory:Postman
      • Theory:Getting data from REST
      • Theory:Posting and deleting data via REST
      • Theory:REST Exception handling
      • Theory:Handling requests with bodies
      • Theory:Domains
      • Theory:HTTP Basic Auth
      • Theory:IP
      • Theory:Authentication and Authorization
      • Theory:OAuth
      • Theory:Java 11 HTTP client
    • Spring boot

  • 练习题

  • Frank - Java与生活

  • Frank - Java API进阶

  • 学习笔记

  • Java
  • Hyperskill - Java
  • Web
Jim
2022-07-19
目录

Theory:HTTP messages

The HTTP protocol relies on the "client-server" architecture that is built on the basis of messaging. HTTP messages are a way to exchange data between clients and servers in the Web. There are two types of messages: requests and responses.

A request is an operation that a client wants to perform on the server, and a response is an answer from the server to an incoming request. Usually, programmers do not need to worry about creating HTTP messages since they are produced by browsers, applications, and web servers.

# The format of messages

In the HTTP protocol, all messages consist of text strings. Both requests and responses have roughly the same standardized format:

  1. Start line

    which may vary:

    • for requests, it indicates the type of request (method) and the URL where to send it (target);
    • for responses, it contains a status code to determine the success of the operation.
  2. Headers which describe the message and convey various parameters.

  3. Body in which the message data is located.

The start line and the header are required attributes, so the other parts may be empty.

The full format can be quite complicated for beginners, so we have considered only its part which is the most important for understanding the general principles.

# The simplified HTTP interaction

Here is a simplified HTTP interaction between a browser client and a server. The client and the server interact through requests and responses which follow the studied format:

img

Note that there are other possible types of client programs, not just a browser. You can even write your own HTTP client and interact with servers. The only requirement is that such a program should always follow the message format.

# Methods

HTTP defines a set of request methods that specify what the desired action will be for a given resource. Despite the fact that their names can be nouns, these query methods are sometimes referred to as HTTP verbs.

Let's look at the most commonly used query methods:

  • GET method is only used to retrieve data from the server;
  • POST method is used to send data to the server;
  • HEAD requests data from the server in the same way as the GET method, but without a response body.

Every time you click on a link, you basically communicate to your browser that you want to GET this page. When you want to log in to your favorite site, you POST your login and password to receive access to it.

There are more available verbs to learn (opens new window). You don't need to memorize them all right now.

# Status codes

For normal operation of computer programs and web pages that work via HTTP, except for the content of the page, the server returns a three-digit code, which specifies the response request. With the help of this code, it is possible to redirect the client to another site or to indicate the change of the page, as well as to detect an error in data processing.

Currently, the standards define five classes of status codes:

1xx: Informational Codes beginning with "1" are called information codes. They report on how client requests are processed.
2xx: Success Messages of this class inform that the action requested by the client has been successfully accepted for processing.
3xx: Redirection It means further action must be taken in order to complete the request.
4xx: Client Error It reports errors on the client's side.
5xx: Server Error The code indicates that the operation was unsuccessful due to the fault of the server.

As an example, if you have successfully loaded a website, the response you received has code 200. You can check this by opening the developer tools of your browser, and clicking on the Networking tab. Then try reloading the web page and you will see the status codes. The combination of keys to open the developer tools can vary. To give you an example, this might be Ctrl + Shift + I or F12 on Windows and Linux, or Cmd + Opt + I on macOS.

You have also probably been in a situation where your browser displays the "404 Not Found" message when you input the address of a page that does not exist. This is how these failure messages usually look:

img

Browsers display error messages so that users can understand that something has gone wrong, rather than continuing to look at the blank page while waiting for the content to be downloaded.

# Conclusion

Let's highlight the main points we've just discussed here:

  • HTTP messages can be of two types: requests and responses.
  • They are composed of the start line, headers, and body. The start line in requests includes method and target, while in responses it includes status code.
  • The commonly used methods in request messages are GET, POST, and HEAD.
  • Status code indicates the response from the server as a three-digit number. It can be one of 5 classes: Informational, Success, Redirection, Client Error, and Server Error.

Now, when you've finished reading the topic, you can visit various sites in a browser and try to guess what your actions look like from a technical point of view.

编辑 (opens new window)
#Web#HTTP
上次更新: 2022/10/12, 17:01:25
Theory:HTTP URL
Theory:MVC

← Theory:HTTP URL Theory:MVC→

最近更新
01
《挪威的森林》
04-14
02
青钢影
04-14
03
Processing strings
02-18
更多文章>
Theme by Vdoing | Copyright © 2022-2023 Jim Frank | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式