亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
Guides Access control CORS Authentication Browser detection using the user agent Caching Caching FAQ Compression Conditional requests Connection management in HTTP 1.x Content negotiation Content negotiation: List of default Accept values Cookies CSP Messages Overview Protocol upgrade mechanism Proxy servers and tunneling Proxy servers and tunneling: Proxy Auto-Configuration (PAC) file Public Key Pinning Range requests Redirections Resources and specifications Resources and URIs Response codes Server-Side Access Control Session Guides: Basics Basics of HTTP Choosing between www and non-www URLs Data URIs Evolution of HTTP Identifying resources on the Web MIME Types MIME types: Complete list of MIME types CSP Content-Security-Policy Content-Security-Policy-Report-Only CSP: base-uri CSP: block-all-mixed-content CSP: child-src CSP: connect-src CSP: default-src CSP: font-src CSP: form-action CSP: frame-ancestors CSP: frame-src CSP: img-src CSP: manifest-src CSP: media-src CSP: object-src CSP: plugin-types CSP: referrer CSP: report-uri CSP: require-sri-for CSP: sandbox CSP: script-src CSP: style-src CSP: upgrade-insecure-requests CSP: worker-src Headers Accept Accept-Charset Accept-Encoding Accept-Language Accept-Ranges Access-Control-Allow-Credentials Access-Control-Allow-Headers Access-Control-Allow-Methods Access-Control-Allow-Origin Access-Control-Expose-Headers Access-Control-Max-Age Access-Control-Request-Headers Access-Control-Request-Method Age Allow Authorization Cache-Control Connection Content-Disposition Content-Encoding Content-Language Content-Length Content-Location Content-Range Content-Type Cookie Cookie2 Date DNT ETag Expect Expires Forwarded From Headers Host If-Match If-Modified-Since If-None-Match If-Range If-Unmodified-Since Keep-Alive Large-Allocation Last-Modified Location Origin Pragma Proxy-Authenticate Proxy-Authorization Public-Key-Pins Public-Key-Pins-Report-Only Range Referer Referrer-Policy Retry-After Server Set-Cookie Set-Cookie2 SourceMap Strict-Transport-Security TE Tk Trailer Transfer-Encoding Upgrade-Insecure-Requests User-Agent User-Agent: Firefox Vary Via Warning WWW-Authenticate X-Content-Type-Options X-DNS-Prefetch-Control X-Forwarded-For X-Forwarded-Host X-Forwarded-Proto X-Frame-Options X-XSS-Protection Methods CONNECT DELETE GET HEAD Methods OPTIONS PATCH POST PUT Status 100 Continue 101 Switching Protocols 200 OK 201 Created 202 Accepted 203 Non-Authoritative Information 204 No Content 205 Reset Content 206 Partial Content 300 Multiple Choices 301 Moved Permanently 302 Found 303 See Other 304 Not Modified 307 Temporary Redirect 308 Permanent Redirect 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 405 Method Not Allowed 406 Not Acceptable 407 Proxy Authentication Required 408 Request Timeout 409 Conflict 410 Gone 411 Length Required 412 Precondition Failed 413 Payload Too Large 414 URI Too Long 415 Unsupported Media Type 416 Range Not Satisfiable 417 Expectation Failed 426 Upgrade Required 428 Precondition Required 429 Too Many Requests 431 Request Header Fields Too Large 451 Unavailable For Legal Reasons 500 Internal Server Error 501 Not Implemented 502 Bad Gateway 503 Service Unavailable 504 Gateway Timeout 505 HTTP Version Not Supported 511 Network Authentication Required Status
characters

在client-server協(xié)議(如HTTP)中,會(huì)話由三個(gè)階段組成:

  1. 客戶端建立TCP連接(或者如果傳輸層不是TCP,則為適當(dāng)?shù)倪B接)。

  2. 客戶端發(fā)送它的請(qǐng)求,并等待答案。

  3. 服務(wù)器處理請(qǐng)求,發(fā)送回答,提供狀態(tài)代碼和適當(dāng)?shù)臄?shù)據(jù)。

從HTTP/1.1開始,連接在完成第三階段后不再關(guān)閉,并且客戶端現(xiàn)在被授予進(jìn)一步的請(qǐng)求:這意味著第二和第三階段現(xiàn)在可以執(zhí)行任意次數(shù)。

建立連接

在client-server協(xié)議中,它是建立連接的客戶端。在HTTP中打開連接意味著在底層傳輸層中啟動(dòng)連接,通常這是TCP。

使用TCP時(shí),計(jì)算機(jī)上的HTTP服務(wù)器的默認(rèn)端口是端口80.也可以使用其他端口,例如8000或8080.要提取的頁的URL包含域名和端口號(hào),但如果是80,則后者可以省略。有關(guān)更多詳細(xì)信息,請(qǐng)參閱識(shí)別Web上的資源。

注意:客戶端 - 服務(wù)器模型不允許服務(wù)器在沒有明確請(qǐng)求的情況下向客戶端發(fā)送數(shù)據(jù)。要解決此問題,網(wǎng)頁開發(fā)人員使用多種技術(shù):通過定期ping服務(wù)器XMLHTTPRequestFetchAPI的使用HTML 的WebSockets API,或類似的協(xié)議。

發(fā)送客戶請(qǐng)求

建立連接后,用戶代理可以發(fā)送請(qǐng)求(用戶代理通常是Web瀏覽器,但可以是其他任何內(nèi)容,例如爬行器)??蛻舳苏?qǐng)求由文本指令組成,由CRLF(回車符,后跟換行符)分隔,分為三個(gè)塊:

  1. 第一行包含一個(gè)請(qǐng)求方法及其參數(shù):

    • 文檔的路徑,即沒有協(xié)議或域名的絕對(duì)URL

    • HTTP協(xié)議版本

  2. 后續(xù)行代表一個(gè)HTTP頭,向服務(wù)器提供關(guān)于什么類型的數(shù)據(jù)是合適的(例如,什么語言,什么MIME類型)或改變其行為的其他數(shù)據(jù)(例如,如果已經(jīng)被高速緩存則不發(fā)送答案)的信息。這些HTTP標(biāo)題形成以空行結(jié)束的塊。

  3. 最后的塊是一個(gè)可選的數(shù)據(jù)塊,它可能包含主要由POST方法使用的更多數(shù)據(jù)。

示例請(qǐng)求

獲取developer.mozilla.org的根頁面(即http://developer.mozilla.org/),并在可能的情況下告訴服務(wù)器用戶代理程序?qū)⑵梅ㄕZ頁面:

GET / HTTP/1.1Host: developer.mozilla.org
Accept-Language: fr

觀察最后的空行,這將數(shù)據(jù)塊從標(biāo)題塊中分離出來。由于沒有Content-Length provided in anHTTP標(biāo)頭,此數(shù)據(jù)塊顯示為空白,表示標(biāo)頭結(jié)束,允許服務(wù)器在收到此空行時(shí)處理請(qǐng)求。

例如,發(fā)送表單的結(jié)果:

POST /contact_form.php HTTP/1.1Host: developer.mozilla.org
Content-Length: 64Content-Type: application/x-www-form-urlencoded

name=Joe%20User&request=Send%20me%20one%20of%20your%20catalogue

請(qǐng)求方法

HTTP定義了一組請(qǐng)求方法,指示對(duì)資源執(zhí)行的所需操作。盡管它們也可以是名詞,但這些請(qǐng)求方法有時(shí)也被稱為HTTP動(dòng)詞。最常見的要求是GETPOST

  • GET方法請(qǐng)求指定資源的數(shù)據(jù)表示。請(qǐng)求使用GET只應(yīng)檢索數(shù)據(jù)。

  • POST方法將數(shù)據(jù)發(fā)送到服務(wù)器,以便它可以更改其狀態(tài)。這是經(jīng)常用于HTML表單的方法。

服務(wù)器響應(yīng)的結(jié)構(gòu)

連接的代理發(fā)送請(qǐng)求后,Web服務(wù)器處理它,最終返回響應(yīng)。與客戶端請(qǐng)求類似,服務(wù)器響應(yīng)由文本指令形成,由CRLF分隔,但分為三個(gè)塊:

  1. 第一行是狀態(tài)行,包含對(duì)所使用的HTTP版本的確認(rèn),其后是狀態(tài)請(qǐng)求(以及其可讀文本中的簡短含義)。

  2. 后續(xù)行代表特定的HTTP標(biāo)頭,給客戶端發(fā)送的數(shù)據(jù)信息(例如,類型,數(shù)據(jù)大小,使用的壓縮算法,關(guān)于緩存的提示)。與用于客戶端請(qǐng)求的HTTP標(biāo)頭塊類似,這些HTTP標(biāo)頭形成以空行結(jié)尾的塊。

  3. 最后的塊是一個(gè)數(shù)據(jù)塊,其中包含可選數(shù)據(jù)。

示例響應(yīng)

成功的網(wǎng)頁回應(yīng):

HTTP/1.1 200 OK
Date: Sat, 09 Oct 2010 14:28:02 GMT
Server: Apache
Last-Modified: Tue, 01 Dec 2009 20:18:22 GMT
ETag: "51142bc1-7449-479b075b2891b"Accept-Ranges: bytes
Content-Length: 29769Content-Type: text/html<!DOCTYPE html... (here comes the 29769 bytes of the requested web page)

通知所請(qǐng)求的資源已永久移動(dòng):

HTTP/1.1 301 Moved Permanently
Server: Apache/2.2.3 (Red Hat)Content-Type: text/html; charset=iso-8859-1Date: Sat, 09 Oct 2010 14:30:24 GMT
Location: https://developer.mozilla.org/ (this is the new link to the resource; it is expected that the user-agent will fetch it)Keep-Alive: timeout=15, max=98Accept-Ranges: bytes
Via: Moz-Cache-zlb05
Connection: Keep-Alive
X-Cache-Info: caching
X-Cache-Info: caching
Content-Length: 325 (the content contains a default page to display if the user-agent is not able to follow the link)<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>301 Moved Permanently</title></head><body><h1>Moved Permanently</h1><p>The document has moved <a href="https://developer.mozilla.org/">here</a>.</p><hr><address>Apache/2.2.3 (Red Hat) Server at developer.mozilla.org Port 80</address></body></html>

通知所請(qǐng)求的資源不存在:

HTTP/1.1 404 Not Found
Date: Sat, 09 Oct 2010 14:33:02 GMT
Server: Apache
Last-Modified: Tue, 01 May 2007 14:24:39 GMT
ETag: "499fd34e-29ec-42f695ca96761;48fe7523cfcc1"Accept-Ranges: bytes
Content-Length: 10732Content-Type: text/html<!DOCTYPE html... (contains a site-customized page helping the user to find the missing resource)

響應(yīng)狀態(tài)碼

HTTP響應(yīng)狀態(tài)代碼指示特定的HTTP請(qǐng)求是否已成功完成。響應(yīng)分為五類:信息響應(yīng),成功響應(yīng),重定向,客戶端錯(cuò)誤和服務(wù)器錯(cuò)誤。

  • 200: 好, 該請(qǐng)求已成功。

  • 301:永久移動(dòng)。該響應(yīng)碼意味著請(qǐng)求資源的URI已被更改。

  • 404: 未找到。服務(wù)器找不到請(qǐng)求的資源。

另請(qǐng)參閱

  • 識(shí)別Web上的資源

  • HTTP標(biāo)頭

  • HTTP請(qǐng)求方法

Previous article: Next article: