Table of Contents
In-depth analysis of HTTP protocol
" >In-depth analysis of HTTP protocol
http introduction
Detailed explanation of HTTP request headers
Http response details
The basic structure of http response
http 响应消息头详解
Expires、Pragma、Cache-Control 设置不缓存
Expires、Pragma、Cache-Control 设置 指定缓存时间
HTTP 请求的细节————通用信息头
Home Web Front-end JS Tutorial In-depth analysis of HTTP protocol

In-depth analysis of HTTP protocol

Sep 21, 2017 am 10:36 AM
http protocol parse

In-depth analysis of HTTP protocol

http Introductionhttp The request part of http Basic structure of requestRequest lineDetailed explanation HTTP request headerHttp Response detailshttp Basic structure of responseStatus linehttp Detailed explanation of response message headerExpires, Pragma, Cache-Control Set not to cacheExpires, Pragma, Cache-Control Settings Specify cache timeHTTP Request details——General information header

http introduction

  1. http protocol is based on tcp/ip protocol

  2. http protocol full name Hypertext Transfer Protocol ( HTTP,HyperText Transfer Protocol)

  3. http protocol version 1.0 1.1 2.0

  4. http 1.0 becomes a short connection, http 1.1 is called a long connection

    The so-called long and short refers to the long connection lasting 1.1 30s and the short connection being disconnected immediately after sending the data

  5. Http defines different methods for interacting with the server. There are four basic methods, namely GET, POST, PUT, and DELETE. The full name of URL is resource descriptor. We can think of it this way: a URL address, which is used to describe a resource on the network, and GET, POST, PUT, and DELETE in HTTP correspond to the search and modification of this resource. Add and delete 4 operations. At this point, everyone should have a general understanding. GET is generally used to obtain/query resource information, while POST is generally used to update resource information.

#The request part of http

Basic structure of http request

Request line

Message header

A blank line

## Content

Request line

Request methods include: post, get, options, delete, trace, put

Commonly used ones are: post, get

The difference between post and get:

GET uses URL or Cookie to pass parameters. And POST puts the data in BODY.

The GET URL will have a length limit, and the POST data can be very large.

POST is safer than GET because the data is not visible on the address bar.

Detailed explanation of HTTP request headers
  1. Accept: Tell the server the files I can accept Type MIME types acceptable to the browser

  2. Accept-Charset: Character set encoding acceptable to the browser

  3. Accept-Encoding: Can accept compressed data in a certain format such as: gzip, compress. The data encoding method that the browser can decode

  4. Accept-Langage: The language supported by the browser

  5. Host: Indicates who the host I am looking for is

  6. ## If-Wodified-Since: Tell the server whether there is a file to be requested in the local cache that contains the time of the requested file // The server receives this request and compares the time to determine whether the file requested by the browser has changed. If Changes will send a new file to the browser. The data will not be sent again without changes. //Note: It will only be returned if the requested content has been modified after the specified date, otherwise 304"Not will be returned. Modified" response.

  7. Referer: Tell the server where I am from. This message header is often used to prevent hot links. My personal understanding on how to prevent hotlinking:

    Hotlinking: Hotlinking means that the service provider itself does not provide services Content, bypassing other beneficial end-user interfaces (such as advertisements) through technical means, directly providing service content of other service providers to end-users on their own websites, defrauding end-users’ browsing and click-through rates. No beneficiaries. Providing resources or providing few resources without any benefit to the real service provider

    ## The value of the referer is what you click on the connection file. Location. referer.startWith("Internal Path");

    public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{        // 防止乱码      response.setContentType("text/html;charset=utf-8");        // 获取输出流      PrintWriter out = response.getWriter();        // 获取用户浏览器 Referer      String referer = request.getHeader("Referer");      if(referer == null || referer.startsWith("http://localhost:8080/本地内部用户web应用路径")){          response.sendRedirect("其他非真正资源网页");          return;      }else{                }      // 内部资源文件        。。。。。。。。。。。  }
    Copy after login

  8. #User-Agent: Tell the server, browser kernel

  9. #Cookie: This is the most important request header information. One
  10. ##Connection: Indicates whether a persistent connection is required. If the Servlet sees that the value here is "Keep-Alive", or see Since the request uses HTTP 1.1 (HTTP 1.1 uses persistent connections by default), it can take advantage of persistent connections and significantly reduce the download time when the page contains multiple elements (such as Applets, images). At this point, the Servlet needs to send a Content-Length header in the response. The simplest way to implement it is: first write the content ByteArrayOutputStream and then calculates its size before actually writing out the contents.
  11. Date: The time when the browser sent the http request.
  12. Content-Length: Indicates the length of the request message body.
  13. ##UA-Pixels, UA-Color, UA-OS, UA-CPU: Sent by some versions of IE browser Non-standard request headers indicating screen size, color depth, operating system and CPU type.

Http response details

The basic structure of http response

## Status line

Multiple headers

One blank line

Entity content

##Status line

Format: http version number status code reason description

# Example : HTTP/1.1 200 OK

The status code is used to indicate the server's processing result of the request. It is a three-dimensional decimal number. Response status codes are divided into 5 categories.

## is used to complete the request , the client needs to further refine the request, for example: the requested resource has been moved to a new address, commonly used 302, 307##400~ 499##500~599
Status code##Meaning
100~199 indicates that the request was successfully received and the client is required to continue submitting. The entire processing process can be completed only with the next request
200~299 indicates that the request was successfully received and the entire processing process has been completed. Commonly used 200
##300~399
The client's request is incorrect. Commonly used 404
## appears on the server side Error, commonly used 500#

http 响应消息头详解
  1. Location:让浏览器重新定位到 指定的 URL

  2. Server:告诉浏览器 服务器的类型

  3. Content-Encoding:服务端能够发送压缩编码类型

  4. Content-Length: 服务器端发送的压缩数据的长度

  5. Content-Langage:服务端发送的语言类型

  6. Content-Type:服务端发送的类型及采用的编码方式

  7. Last-Modified:服务端对该资源最后的修改(更新)时间

  8. Refresh:服务端要求浏览器在指定的时间,刷新,然后访问指定的页面路径

  9. Content-Disposition:attachmen;filename=aaa.zip 服务端要求客户端一下载文件的方式打开该文件,即告诉浏览器有文件需要下载

  10. Transfer-Encoding:传送数据到客户端的方式

  11. Set-Cookie:服务端发送到客户端的暂存数据

  12. Cache-Control:告诉浏览器如何缓存页面数据

  13. Expires:告诉浏览器如何缓存页面数据 参数 -1 不缓存

  14. Pragma:告诉浏览器如何缓存页面数据

  15. Connection:维护客户端和服务端的连接关系 是否保持连接

  16. Date:服务端响应客户端的时间

Expires、Pragma、Cache-Control 设置不缓存
// 指定该页面不缓存   ie浏览器内核response.setDateHeader("Expires",-1);// 兼容设置response.setHeader("Cache-Control","no-cache");response.setHeader("Pragma","no-cache");
Copy after login

Expires、Pragma、Cache-Control 设置 指定缓存时间
// 指定该页面缓存指定时间   ie浏览器内核response.setDateHeader("Expires",System.currentTimeMillis()*3600*1000*24;
Copy after login

HTTP 请求的细节————通用信息头

通用信息头指既能用于请求,又能用于响应的一些消息头

Cache-Control:no-cache

Pragma:no-cache

Connection:close/Keep-Alive

Date:Tue,。。。

The above is the detailed content of In-depth analysis of HTTP protocol. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1677
14
PHP Tutorial
1279
29
C# Tutorial
1257
24
Detailed explanation of Oracle error 3114: How to solve it quickly Detailed explanation of Oracle error 3114: How to solve it quickly Mar 08, 2024 pm 02:42 PM

Detailed explanation of Oracle error 3114: How to solve it quickly, specific code examples are needed. During the development and management of Oracle database, we often encounter various errors, among which error 3114 is a relatively common problem. Error 3114 usually indicates a problem with the database connection, which may be caused by network failure, database service stop, or incorrect connection string settings. This article will explain in detail the cause of error 3114 and how to quickly solve this problem, and attach the specific code

Parsing Wormhole NTT: an open framework for any Token Parsing Wormhole NTT: an open framework for any Token Mar 05, 2024 pm 12:46 PM

Wormhole is a leader in blockchain interoperability, focused on creating resilient, future-proof decentralized systems that prioritize ownership, control, and permissionless innovation. The foundation of this vision is a commitment to technical expertise, ethical principles, and community alignment to redefine the interoperability landscape with simplicity, clarity, and a broad suite of multi-chain solutions. With the rise of zero-knowledge proofs, scaling solutions, and feature-rich token standards, blockchains are becoming more powerful and interoperability is becoming increasingly important. In this innovative application environment, novel governance systems and practical capabilities bring unprecedented opportunities to assets across the network. Protocol builders are now grappling with how to operate in this emerging multi-chain

Analysis of the meaning and usage of midpoint in PHP Analysis of the meaning and usage of midpoint in PHP Mar 27, 2024 pm 08:57 PM

[Analysis of the meaning and usage of midpoint in PHP] In PHP, midpoint (.) is a commonly used operator used to connect two strings or properties or methods of objects. In this article, we’ll take a deep dive into the meaning and usage of midpoints in PHP, illustrating them with concrete code examples. 1. Connect string midpoint operator. The most common usage in PHP is to connect two strings. By placing . between two strings, you can splice them together to form a new string. $string1=&qu

How to implement HTTP streaming using C++? How to implement HTTP streaming using C++? May 31, 2024 am 11:06 AM

How to implement HTTP streaming in C++? Create an SSL stream socket using Boost.Asio and the asiohttps client library. Connect to the server and send an HTTP request. Receive HTTP response headers and print them. Receives the HTTP response body and prints it.

Apache2 cannot correctly parse PHP files Apache2 cannot correctly parse PHP files Mar 08, 2024 am 11:09 AM

Due to space limitations, the following is a brief article: Apache2 is a commonly used web server software, and PHP is a widely used server-side scripting language. In the process of building a website, sometimes you encounter the problem that Apache2 cannot correctly parse the PHP file, causing the PHP code to fail to execute. This problem is usually caused by Apache2 not configuring the PHP module correctly, or the PHP module being incompatible with the version of Apache2. There are generally two ways to solve this problem, one is

Analysis of new features of Win11: How to skip logging in to Microsoft account Analysis of new features of Win11: How to skip logging in to Microsoft account Mar 27, 2024 pm 05:24 PM

Analysis of new features of Win11: How to skip logging in to a Microsoft account. With the release of Windows 11, many users have found that it brings more convenience and new features. However, some users may not like having their system tied to a Microsoft account and wish to skip this step. This article will introduce some methods to help users skip logging in to a Microsoft account in Windows 11 and achieve a more private and autonomous experience. First, let’s understand why some users are reluctant to log in to their Microsoft account. On the one hand, some users worry that they

A Practical Guide to Java JSON Processing: A Data Manipulation Masterclass A Practical Guide to Java JSON Processing: A Data Manipulation Masterclass Mar 09, 2024 am 09:10 AM

JSON, Jackson, Gson, data operations, Java introduction jsON (javascript object notation) is a lightweight data exchange format widely used in WEB applications and APIs. Java provides a wealth of libraries to process JSON data, the most popular of which are Jackson and Gson. This article will mainly introduce how to use these two libraries to read, write and modify JSON data. Read JSON data JacksonObjectMappermapper=newObjectMapper();JsonnoderootNode=mapper.readTree(jsonStr);GsonG

Comparison of Java libraries for XML parsing: Finding the best solution Comparison of Java libraries for XML parsing: Finding the best solution Mar 09, 2024 am 09:10 AM

Introduction XML (Extensible Markup Language) is a popular format for storing and transmitting data. Parsing XML in Java is a necessary task for many applications, from data exchange to document processing. To parse XML efficiently, developers can use various Java libraries. This article will compare some of the most popular XML parsing libraries, focusing on their features, functionality, and performance to help developers make an informed choice. DOM (Document Object Model) parsing library JavaXMLDOMAPI: a standard DOM implementation provided by Oracle. It provides an object model that allows developers to access and manipulate XML documents. DocumentBuilderFactoryfactory=D

See all articles