JavaWeb (two) - Http protocol

1. Http Introduction

HTTP ( Hypertext Transfer Protocol ) is a simple request - response protocol , which typically runs on top of TCP. HTTP protocol works in a client - server architecture on. Browser as an HTTP client URL that is WEB server sends all requests to the server via HTTP. Web server according to the received request, transmits the response information to the client.

  • Text: html, string, ~ ....
  • Hypertext: pictures, music, video, location, map .......
  • The default port: 80

Https: security

  • Default Port: 443

2. Http protocol features

No connection : Meaning No limitation is attached only one request per connection. After the server processes client requests and receives the customer's response, i.e., disconnected. In this way it can save transmission time.
Stateless : HTTP protocol is stateless protocol. Stateless means the agreement for the transaction has no memory capability . If the lack of state means that the subsequent processing required in front of the information, it must be retransmitted, which may result in the amount of data transmitted for each connection is increased. On the other hand, when it does not require previous information in response to a faster server.
Detailed description:
Here Insert Picture Description

3. Two Times

  • http1.0

    • HTTP / 1.0: the client may connect with the web server, a web can only get resources, disconnect
  • http2.0

    • HTTP / 1.1: the client may connect with the web server, a plurality of web resources may be obtained

Step 4. Http request / response

(1) client to connect to the Web server
(2) sends an HTTP request
(3) server accepts the request and returns an HTTP response
(4) to release the TCP connection is connected
(5) client browser parses the HTML content

5. Http Request

  • Client - requesting (the Request) - Server

Baidu:

Request URL:https://www.baidu.com/   请求地址
Request Method:GET    get方法/post方法
Status Code:200 OK    状态码:200
Remote(远程) Address:14.215.177.39:443
Accept:text/html  
Accept-Encoding:gzip, deflate, br
Accept-Language:zh-CN,zh;q=0.9    设置语言
Cache-Control:max-age=0
Connection:keep-alive

(1) Request line

  • Request line request method: GET

  • Request mode: the Get, Post , the HEAD, DELETE, PUT, TRACT ...

    • get: request parameters capable of carrying relatively small, the size is limited, the data will be displayed in the URL address bar of the browser, not safe, but efficient
    • post: request parameters can carry no limit, no size limit, does not display the data content in the URL address bar of the browser security, but not efficient

(2) message header

Accept:告诉浏览器,它所支持的数据类型
Accept-Encoding:支持哪种编码格式  GBK   UTF-8   GB2312  ISO8859-1
Accept-Language:告诉浏览器,它的语言环境
Cache-Control:缓存控制
Connection:告诉浏览器,请求完成是断开还是保持连接
HOST:主机..../.

6. Http response

  • Server - client response -----

Baidu:

Cache-Control:private    缓存控制
Connection:Keep-Alive    连接
Content-Encoding:gzip    编码
Content-Type:text/html   类型

(1) in response to body

Accept:告诉浏览器,它所支持的数据类型
Accept-Encoding:支持哪种编码格式  GBK   UTF-8   GB2312  ISO8859-1
Accept-Language:告诉浏览器,它的语言环境
Cache-Control:缓存控制
Connection:告诉浏览器,请求完成是断开还是保持连接
HOST:主机..../.
Refresh:告诉客户端,多久刷新一次;
Location:让网页重新定位;

(2) the response status code
200: Successful request response 200
3xx: Redirection Request

  • Redirect: I'll give you back to your new location to go;

4xx: Resource not found 404

  • Resources do not exist;

5xx: Server Error Code 500 502: Bad Gateway

7. The main difference between the Http and Https

(1) https protocol ca need to apply for a certificate, generally less free certificates, thus requiring a fee.
(2) HTTP Hypertext transfer protocol, information is transmitted in the clear , HTTPS is a security with SSL (Secure Sockets Layer) encrypted transmission protocol .
(3) http and https use is completely different connections, with the port are not the same, the former is 80, which is 443.
(4) http connection is very simple, is stateless; the HTTPS protocol is constructed from SSL + HTTP protocol may be encrypted transmission, network authentication protocol, the http protocol than security.

8. Common interview questions

When your browser address bar and press Enter to enter the address of a page to be able to show the moment back, I experienced what?
Reference blog: https: //blog.csdn.net/wuhenliushui/article/details/20038819
This section to be more

Published 62 original articles · won praise 2 · Views 2733

Guess you like

Origin blog.csdn.net/nzzynl95_/article/details/104190011