HTTP Basics

1. HTTP protocol (HyperText Transfer Protocol, Hypertext Transfer Protocol) is the most widely used network transmission protocol on the Internet, and all WWW files must comply with this standard.

HTTP is a communication protocol based on TCP/IP to transfer data (HTML files, image files, query results, etc.).

Communication process:

 

The Http protocol consists of Http request and Http response. When you enter a URL in the browser to visit a website, your browser will encapsulate your request into an Http request and send it to the server site. After the server receives the request, it will organize the response The data is encapsulated into an Http response and returned to the browser. That is, there is no response without a request.

2. HTTP request and response:

The request message that the client sends an HTTP request to the server includes the following format: request line, request header, blank line and request data. For example:

Accept:

text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8

Accept-Encoding:

gzip, deflate, br

Accept-Language:

zh-CN, zh; q = 0.9

Connection: //keep the connection

keep-alive

Cookie: //Important!

LIVE_BUVID=AUTO7915222124019414; fts=1522212425; sid=cz06a1ca; UM_distinctid=16276eceacd173-01185465e6e735-4446062d-100200-16276eceacf2e2; buvid3=6E5942CA-6BDB-4B0A-833D-869896A0D803691infoc; rpdid=kmkkkpxoswdosiipmolqw; CURRENT_QUALITY=80; finger=edc6ecda; DedeUserID=141366726; DedeUserID__ckMd5=b003b2db3538137a; SESSDATA=086350d0%2C1527560093%2C3ca951e5; bili_jct=185f065f6213a32ecbcc6566cea28a93

Host:

www.bilibili.com

Upgrade-Insecure-Requests:

1

User-Agent:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36

Server response: status line, message header, blank line and response body, for example:

HTTP / 1.1 200 OK Date : Mon , 27 Jul 2009 12 : 28 : 53 GMT Server : Apache Last - Modified : Wed , 22 Jul 2009 19 : 15 : 56 GMT , the status code is 304, directly read the local cache ETag : "34aa387-d-1568eb00" Accept - Ranges : bytes Content - Length : 51 Vary                 :Accept-EncodingContent-Type: text/plain  

Common request methods: GET POST

Generally, the request byte length of the GET method is limited by the browser or server, but the POST method does not.

If the GET method is used to submit the account password, it is not safe, the account password will be displayed in the URL in plain text, and the default web page access is the GET method.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
    <form action="#" method="post">
        <input type="text" name="user">
        <input type="text" name="password">
        <input type="submit" value="提交">
    </form>
</body>
</html>

Common status codes:

200 - Request succeeded

301 - Resource (web page, etc.) permanently moved to another URL

404 - The requested resource (page, etc.) does not exist

500 - Internal server error

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325246209&siteId=291194637
Recommended