Retake Course day59 (Django http)

Source: Internet
Author: User

An Introduction to HTTP protocol

HTTP protocol (Hyper Text Transfer Protocol): Hypertext Transfer Protocol, is based on the application layer of object-oriented protocol, TCP protocol and IP to transmit data, request and response is the basic concept of HTTP protocol.

The HTTP protocol works on the client and server architectures, and the browser sends all requests to the HTTP server as HTTP clients via URLs.

Two HTTP Features

1 Simple and fast: When a browser sends a request to the server, it only needs to transfer the method and path of the request.

Request method: Get,post,head, different methods have different contact types.

2 Flexible: HTTP transports can be arbitrary data types, controlled by Content_Type.

3 No connection: Limit only one request at a time, and the server disconnects the link when it processes the request and is answered by the client. This saves transmission time.

4 stateless: The ability to deal with things without memory.

Three HTTP request Protocol

What is called request protocol: The data format of the browser request server, also called the request format

Format of Request:

Request the first line        ,//Request path Protocol and version, for example: get/index.html http/1.1 request header information;      //Request Header name: request header content, that is, the key:value format, for example: Host:localhost blank line;           //used to separate the request body from the request body.         //Get no request body, only post has request body.

GET Request:

Get/562f25980001b1b106000338.jpg http/1.1host    img.mukewang.comuser-agent    mozilla/5.0 (Windows NT 10.0; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/51.0.2704.106 safari/537.36accept    image/webp,image/*,*/*;q= 0.8Referer    http://www.imooc.com/Accept-Encoding    gzip, deflate, Sdchaccept-language    zh-cn,zh;q=0.8

HTTP default request method is get, data follows URL, by? Split open URL and data, multiple parameters are separated by the & symbol, the space to the + number, the text will be directly encrypted with BASE64, no request body data, size is limited, and the requested data will be exposed in the address bar.

Get common operations: give the URL directly in the Address bar, click a hyperlink to the page, and the form form is a GET request by default, but can be set as a POST request.

POST request:

post/http1.1host:www.wrox.comuser-agent:mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;. NET CLR 2.0.50727;. NET CLR 3.0.04506.648;. NET CLR 3.5.21022) content-type:application/ X-www-form-urlencodedcontent-length:40connection:keep-alivename=professional%20ajax&publisher=wiley

Post Request method: The data is placed in the request body, the requested data size is not limited, for GET requests, the POST request data is more secure.

Quad HTTP Response Protocol

When the server receives a client request, it returns an HTTP response message.

Response Format: The HTTP response is also made up of four parts: the first line of response (status code), the response header, the blank line, and the response body.

Instance:

http/1.1, Okdate:fri 06:07:21 gmtcontent-type:text/html; charset=utf-8
The first part: The status line, consists of the HTTP protocol version number, the status code, the status message three parts. The first behavior status line, (http/1.1) indicates that the HTTP version is 1.1, the status code is 200, and the status message is (OK) The second part: The message header, which describes some additional information the client wants to use the second and third behavior message header, Date: The day and time the response was generated ; Content-type: Specifies the MIME type of HTML (text/html), the encoding type is the third part of UTF-8: A blank line, a blank line after the message header is required Part IV: Response body, the server returns text information to the client. The HTML portion following the empty line is the response body.

Meaning of the Status Code response:

The status code consists of three digits, and the first number defines the category of the response, divided into five categories: 1xx: Indicates that the request has been received and continues processing 2xx: Success-Indicates that the request has been successfully received, understood, Accept 3xx: Redirect-A further action must be taken to complete the request 4xx: Client Error-Request syntax error or request not implemented 5XX: server-side error-the server failed to implement a legitimate request common status code: OK                        //Client Request success Bad Request               //Client request has a syntax error and cannot be understood by the server unauthorized              //Request unauthorized, this status code must be used together with the Www-authenticate header domain Forbidden                 //server received the request, However, the denial of service is                 not Found//request resource does not exist, eg: the wrong urlinternal server error//     Server error has occurred//servers unavailable        // The server is currently unable to process client requests and may return to normal after some time

Request: Header response: response header.

User_aaent: Determines whether the request is sent by the browser.

Cookies: Do verification protection

Host: The requested data

Referer: Anti-theft chain related issues, the source of this jump

Accept: Receive data

1, host requests the Web server domain name address2, user-agenthttp Details of the browser type that the client is running. With this header information, the Web server can determine the type of browser for the HTTP request client. 3, accept specifies the type of content that the client can receive, and the order of the content type indicates the order in which the customer is received4, accept-Lanuage Specifies the language that the HTTP client browser uses to display the return information preference5, accept-encoding specifies that the Web server that the client browser can support returns the content compression encoding type. Indicates that the server is allowed to compress the output before it is sent to the client to conserve bandwidth. The return compression format that the client browser can support is set here. 6, accept-Charsethttp the set of character encodings that the client browser can accept7, content-Type Displays the content type submitted by this HTTP request. Typically only post submissions need to set this property about content-The type attribute value has the following two types of encoding: (1) "application/x-www-form-urlencoded": the type of encoding used when the form data is submitted to the server, the default value is "application/x-www-form-urlencoded ". However, this encoding is inefficient when sending large amounts of text to the server, including text or binary data that contains non-ASCII characters. (2) "Multipart/form-data": When the file is uploaded, the type of encoding used should be "multipart/form-Data, which can send both textual and binary data uploads. When submitted as form data, you can use the application/x-www-form-urlencoded "When a file is submitted, the" Multipart/form-data "encoding type is required.
View Code

 

Retake Course day59 (Django http)

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.