Python/http protocol

Source: Internet
Author: User

Python/http Protocol HTTP protocol:HTTP is a communication protocol, which specifies the format of the content that the client sends to the server, and the content format that the server sends to the client. In fact, we have to learn the two formats! The format that the client sends to the server and the ' request protocol '; The format that the service sends to the client is called the ' response protocol 'HTTP Features:HTTP Features: Full name is the Hypertext Transfer Protocol, based on the request/Response mode HTTP is a stateless protocol. Stateless is that you visit multiple times, the first visit and the second visit have no relation URL: Uniform Resource Locator, is a URL: protocol name://domain: Port/path. For example: Http://www.baidu.com:80/index.htmlurl, the URL is entered when accessing, the server will parse the URL into the IP address Request protocol format:
1 request the first line;  //Request Path Protocol and version, for example: get/index.html http/1.12 request header information;// Request Header name: request header content, that is, the key:value format, For example: Host:localhost3 blank line,     // used to separate 4 request body from the request body  .   //Get no request body, only post has request body.

The client (browser) sends the protocol to the server (server view)
11, request the first line (GET request method, directly expose the data behind the URL) get/data content, HTTP protocol version2Get/favicon.ico http/1.132, request header information4host:127.0.0.1:8800#access to IP and ports5connection:keep-Alive6user-agent:mozilla/5.0 (Windows NT 10.0; WOW64)7accept:image/webp,image/*,*/*;q=0.88Referer:http://127.0.0.1:8800/#View Access links and paths (see if the customer is coming through their own link or something else)9accept-Encoding:gzip, deflate, SDCH, BRTenaccept-language:zh-cn,zh;q=0.8#Supported Languages One because the HTTP protocol is stateless and you want to save the result information, you can A cookie container Access, cookie is a dictionary, content is returned to us by the server - a cookie is a container and a dictionary. -3, blank line (to make the request interpretation information and the request data area separate, add a blank line) the  -4, the request body (data)-----------(GET request body does not exist) post will put the data in the request body, get will put the data behind the URL address bar
Post is higher than get safety factor, get to put data in URL pass? , there is a limit to the length of the URL. Post puts the data in the request body, the data length does not limit the GET Request: HTTP Default Request method is Getget no request body data must be within 1K GET request data will be exposed in the address bar of the browser GET request common operation: 1, in the browser's address bar in bytes given the URL, Name must be a GET request 2, click on the page hyperlink also must be GET request 3, submit the form, the form by default use GET request, but can be set to post
1GET 127.0.0.1:8090/login http/1.1:get request, the request server path is 127.0.0.1:8090/login, the protocol is 1.1;2 Host:localhost: The requested host name is localhost;3*user-agent:mozilla/5.0 (Windows NT 5.1; rv:5.0) gecko/20100101 firefox/5.0: Browser-and OS-related information. Some websites show the user's system version and browser version information, all by getting user-Agent header information;4accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8: Tells the server that the current client can receive the document type, which actually contains the */*, it means that anything can be received;5accept-language:zh-cn,zh;q=0.5: Languages supported by the current client, language-related information can be found in the browser's tools? options;6accept-Encoding:gzip, deflate: supported compression format. When data is passed on the network, the server may compress the data before sending it;7accept-charset:gb2312,utf-8;q=0.7,*;q=0.7: The encoding supported by the client;8connection:keep-Alive: The client supports the link mode, maintains a period of time link, defaults to 3000ms;9Cookie:jsessionid=369766fdf6220f7803433c0b2de36d98: Because it is not the first time that this address is accessed, the cookie sent over the last server response in the request is sent to the request in a concurrent The name of this cookie is Jsessionid
Post request 1. Data does not appear in the Address bar 2. There is no limit on the size of the data 3. There is a request body 4. If there is Chinese in the request body, the form can be used to send a POST request using URL encoding, but the 3 form defaults to the Getpost request is available, and the GET request does not have the request body Referer Source of passenger traffichttp://localhost:8080/hello/index.jsp: The request from which page, for example you on Baidu Click Link to here, then referer:http://www.baidu.com If you are entering the address directly in the address bar of the browser, then there is no Referer the request header; content-type:application/x-www-form-urlencoded: The data type of the form, indicating that the data is encoded using URL format, and that the URL -encoded data is prefixed with "%". followed by the two-bit of the decimal system. content-length:13: The length of the request body, represented here as 13 bytesKeyword=hello: Request body content! Hello is the data entered in the form, keyword is the name of the form field< Span class= "S5" > response protocol: The format of the response protocol is as follows: Response header information for the first line of the response the content is sent by the server to the browser, and the browser is displayed according to the response content. Encounter will open a new line loads load, so sometimes the picture is more, the content will be displayed first, and then the picture is a single load out http/1.1: The response protocol is HTTP1.1, the status code of 200 indicates a successful request OK is the explanation of the status code server:wsgiserver/0.2 cpython/3.5.2: Version information of the server; Content-type:text/html;charset=utf-8: The response body uses an encoding of UTF-8 ; content-length:724: The response body is 724 bytes set-cookie:jsessionid=c97e2b4c55553eab46079a4f263435a4; Path=/hello: Response to client cookiedate:wed,25 SEP 04:15:03 GMT: Response time, which may have a 8-hour time zone difference status code: The response header is important to the browser, and he explains the true meaning of the response. For example, 200 indicates that the response was successful and 302 indicates redirection, which means the browser needs to send a new request again. 200: The request succeeds, the browser will display the response body content (usually HTML) in the browser 302: Redirect, when the response code is 302, indicating that the server requires the browser to resend a request, the server sends a response header location, It specifies the URL of the new request 404: The requested resource was not found, stating that the client failed to request a resource that does not exist (as long as the 4 error is the client's problem) 500: The request resource was found, but there was an error inside the server (as long as the error at the beginning of the 5 is a service-side problem)
1 When a user requests index.html for the first time, the server adds a response header called Last-modified.
This header describes the last modification time of the index.html, and the browser caches the index.html content and the last response time.
When the user requests index.e=html a second time, the request contains a header called Tf-modified.
Its value is the first time the server responds to the browser's value via Last-modified, that is, the inde.html last modified time,
If-modified-since request header is to tell the server, I here browser cache index.html Last modified time is this,
You see the heart in the index.html last modified time is not this, if it is, then you do not have to respond to this index.html content,
I will show the contents of the buffer directly. The server sends a response code of 304, which means that the index.html is the same as the last cache in the browser.
No need to send again,
The browser can display its own buffer page, if the comparison is different, then the INDEX.HRML has been modified, the server will respond 200

Other response Headerstell the browser not to cache the response headers:
    • Expires:-1;
    • Cache-control:no-cache;
    • Pragma:no-cache;
The response header is automatically refreshed and the browser requests http://www.baidu.com after 3 seconds :
    • refresh:3;url=http://www.baidu.com Specifies the response header in HTML 
in the HTMl page, you can use <meta http-equiv= "" content= "> to specify the response header, for example, in the index.html page < Meta http-equiv= "Refresh" content= "3;url=http://www.baidu.com" >, indicating that the browser will only show index.html page 3 seconds, and then automatically jumps to http://www.baidu.com. For more information, please see the link: http://www.cnblogs.com/yuanchenqi/articles/6000358.html

Python/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.