goweb-http protocol

A first link to my another blog about the HTTP
will be some slow first visit ~~~

http protocol

Because writing Web applications must understand HTTP, so we introduced the HTTP

Introduction to the HTTP protocol

HTTP Hypertext Transfer Protocol (HTTP-Hypertext transfer protocol), is an application layer of the
object-oriented protocols, due to its simple, fast way for distributed hypermedia information system. In 1990 it
put forward, after years of use and development, has been continuously improved and expanded. It is a browser provides detailed
rules for communication between each other and the Web server, the World Wide Web document transfer protocol to transfer data via the Internet.
Content delivery client and server communicate our message called
HTTP communication is a rule which specifies the client sends to the server message format, Regulations
set the server to the client's message format. We have to learn is actually two messages. The client sends
to the server is called a "request packet", the server transmits to the client is referred to as "response packet."

HTTP protocol development process

Formerly known as Hypertext Transfer Protocol is Xanadu (Xanadu) project, the concept of hypertext is ˙ Ted Nelson (Ted
Nelson) proposed in the 1960s. After entering Harvard University, Nelson hypertext protocol and we have been committed to the project
study, but he never publicly published data. In 1989, Tim Berners ˙ ˙ Lee (Tim Berners Lee) at CERN (Ou
Zhou Nuclear Research = European Organization for Nuclear Research) as a software consultant
time, developed a program to lay the World Wide Web (WWW = World Wide Web) basis. 1990 Nian
December hypertext for the first time on-line at CERN. The summer of 1991, following protocols such as Telnet, Hypertext Transfer Association
proposed to be part of the Internet and many other protocols.
At that time, Telnet protocol solves the control type of communication between one computer and another computer
requirements. Mail agreement resolves a sender communication requirements of a small amount of information to staff. File transfer protocol to resolve
a computer to acquire a file from another communication requires a computer batch, but it does not have a file acquisition side
edges of the file or files of some processing function. News Transfer Protocol addresses the many news broadcast communication
requirements. The hypertext to solve the communication requirements are: acquiring and displaying stored in multiple computers on a single computer in
the text, data, images and other types of files; it consists of two parts: hypertext transfer protocol and hypertext mark
Markup language (HTML). The birth of HTTP, HTML and browser to the popularity of the Internet has brought a leap.

Session of the HTTP protocol

Communication process between the browser and the server to go through four steps: build -> Hair -> back -> OFF

WEB browser and the server connection process is short, and each handles only one connection request and response. For each
visit a page, the browser and the WEB server must establish a separate connection.

All communication between the browser to the WEB server is completely independent separate request and response pair.

The difference between ## HTTP1.0 and HTTP1.1

In HTTP1.0 version, the browser requests a web page with an image, due to the server and download the image
to open a new connection between; but in HTTP1.1 version, allowing the browser to get the corresponding current request all
resources and then disconnected, improve the efficiency of HTTP 1.1 is currently the most widely used version, but the latest version is HTTP 2.0, and
said the HTTP / 2. HTTP 2.0 on the open Internet will only be used https: // URL. The HTTPS, i.e., the SSL (the Secure
HTTP over Socket Layer, Secure Sockets Layer), is actually performed in the upper HTTP SSL / TLS connection
communication.
Note: SSL was originally developed by Netscape, followed by the IETF (Internet Engineering Task Force,
to take over the Internet Engineering Task Force) and renamed it TLS (Transport Layer Security, Transport Layer Security Association
Conference)

Request packet

  • Message format

    • Request the first line (request line);
    • Request header information (header request);
    • Blank line;
    • Request body;
  • Get request
GET /Hello/index.jsp HTTP/1.1
Accept: */*
Accept-Language: zh-CN
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64;
Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;
Media Center PC 6.0; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Host: localhost:8080
Connection: Keep-Alive
Cookie: JSESSIONID=C55836CDA892D9124C03CF8FE8311B15

Get request no request body, Post request only request body

GET /Hello/index.jsp HTTP / 1.1: GET request, the request server path
Hello / index.jsp, 1.1 protocol;

  • Host: localhost: localhost requested host name;

  • User-Agent: Mozilla / 4.0 (compatible; MSIE 8.0 ...: associated with the browser and the OS

information. Some sites will display the user's browser version and system version information, this is by acquiring User-
Agent header come;

  • The Accept: / : tell the server, document type for the current client can receive, / , it means
    what can be received;

  • Accept-Language: zh-CN: The current language supported by the client, can be a tool in the browser

 options to find the language-related information;

  • Accept-Encoding: gzip, deflate: Supported compression formats. When data is transmitted over the network,
    it may be a server will then send the data compression;

  • Connection: keep-alive: Client support linking, link period of time, silent
    thought 3000ms;

  • Cookie: JSESSIONID = 369766FDF6220F7803433C0B2DE36D98: because it is not
    the first visit this address, it will be the last response sent from the server in the Cookie request
    transmitted together in the past in the request.

  • Post Request
    POST request method requires the property to form a tag post

POST /Hello/target.html HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml,
image/gif, image/pjpeg, application/x-ms-xbap, */*
Referer: http://localhost:8080/Hello/
Accept-Language: zh-CN
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64;
Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729;
Media Center PC 6.0; .NET4.0C; .NET4.0E)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: localhost:8080
Content-Length: 14
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: JSESSIONID=774DA38C1B78AE288610D77621590345

Referer: HTTP: // localhost: 8080 / the Hello / index.jsp: which page requests from, for example, you are a hundred
on the degree to click on the link here, then Referer: http://www.baidu.com; if you are browsing earth's
address directly into the address bar, then there is no Referer request of the head;

  • Content-Type: application / x- www-form-urlencoded: form data type, description
    will use the format of the encoded data url; url-encoded data is a "%" prefix, followed by two 16 into the
    system, e.g. "Chuanzhi" url word using UTF-8 encoding used was "% E4% BC% A0% E6% 99% BA";

  • Content-Length: 13: length of the request body, here represented 13 bytes.

  • keyword = hello: content request body! hello data is entered in a form, keyword is the form
    name field.

Response message

  • Message format
    • The first line of response (response line);
    • In response to the header information (header response);
    • Blank line;
    • In response thereof;
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=UTF-8
Content-Length: 274
Date: Tue, 07 Apr 2015 10:08:26 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
  • HTTP / 1.1 200 OK: the HTTP1.1 response protocol, status code 200 indicating the request was successful;
  • Server: Apache-Coyote / 1.1: the version information of the server;

  • Content-Type: text / html; charset = UTF-8: the response code used was in UTF-8;

  • Content-Length: 274: 274 bytes for the response member;

  • Date: Tue, 07 Apr 2015 10:08:26 GMT: response time, which may have eight hours time
    difference zone;

The response status code

  • HTTP status code is used to tell the client, HTTP server results in the expected Response. HTTP / 1.1
    protocol is defined in the Class 5 status code, status code of three digits, the first digit of the response defines the classes
    do not

    • 1XX message - indicates that the request has been successfully received, processing continues

    • 2XX success - indicates that the request has been successfully received, understood, accepted

    • Redirection 3XX - request must be completed for further processing

    • 4XX Client Error - The request has a syntax error or a request can not be achieved

    • 5XX server-side error - server failed to achieve a legitimate request

  • Response code is important for browsers that tells the browser in response to the results, a common status codes are:
    • 200: request was successful, the browser content body will respond (usually html) displayed in the browser;

    • 404: The requested resource is not found, indicating that the client requests a resource error does not exist;

    • 500: requested resource is found, but the internal server error occurred;

    • 302: Redirect, when the response code is 302, indicating that the server requires a browser to re-send the request,
      the server sends a response header Location, which specifies the address of the new URL request;

Guess you like

Origin www.cnblogs.com/ygjzs/p/12046155.html