Java Development Series-http Protocol

Source: Internet
Author: User

Overview

HTTP (hypertext Transfer Protocol) is one of the most widely used network protocols on the Internet. This protocol is used to specify the format of the communication data.

HTTP request

The browser sends data to the server called 请求 . The HTTP protocol specifies the request component: The request line, the request header, the request body.

Request Line: The first line of the request information
Request Header: The second line of the request information ends with a blank line
Request body: Empty line of content只有POST请求才有请求体

View request information for a GET request via Google Chrome

The request line describes how the request is made, such as a GET or POST request. There are also resources, protocols/versions to access.

Get vs. Post requests

GET请求会把参数放在url后面而POST请求会把参数放在请求体中,并且GET参数有大小限制,POST请求没有限制。GET请求没有请求体,而POST有请求体用于存放参数。

HTTP protocol version

HTTP 1.0 Specifies that the browser and the server only maintain a brief connection, each request of the browser needs to establish a TCP connection with the server, the server completes the request processing immediately after disconnecting the TCP connection, the server does not track each customer also does not log past requests.

Common HTTP request headers
Accept: text/html, image/*  --支持数据类型 格式 大类型/小类型 ,mime类型Accept-Charset: ISO-8859-1 --字符集Accpet-Encoding: gzip --支持压缩Accept:-Language: zh-cn --语言环境Host: localhost:8080 --访问主机If-Modified-Since: Tue, 11 Jul 2000 18:27:52 GMT --缓存文件最后修改的时间Referer: http://localhost:8080/index.html -- 来自哪个页面 防盗链User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36Cookie:Connection: close/Keep-Alive --连接状态Date:  Tue, 11 Jul 2000 18:27:52 GMT --时间

HTTP 1.1 Persistent connection, also need to add new request header to help implement, for example, when the value of the connection request header is keep-alive, the client notifies the server to keep the connection after returning the result of the request, and when the value of the connection request header is close, The client notifies the server to close the connection after returning the result of this request. HTTP 1.1 also provides request headers and response headers related to mechanisms such as authentication, state management, and cache caching.

HTTP response

The server writes data to the browser called 响应 . The HTTP protocol specifies the response component: Response line, response header, and response body.

View a request line for a GET request via Google Chrome


Response Line contains protocol version status Code, common status code

    • 200 The service side has a good response success
    • 302 redirects
    • 304
    • 404
    • 500

Java Development Series-http Protocol

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.