Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does the HTTP protocol work

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "what is the working principle of HTTP protocol". The editor shows you the operation process through an actual case, and the operation method is simple, fast and practical. I hope this article "what is the working principle of HTTP protocol" can help you solve the problem.

HTTP protocol (HyperText Transfer Protocol, Hypertext transfer Protocol) is the most widely used network transfer 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, picture files, query results, etc.).

:::

Introduction to HTTP

HTTP protocol is the abbreviation of Hyper Text Transfer Protocol (Hypertext transfer Protocol). It is a transport protocol used to transfer hypertext from a WWW:World Wide Web server to a local browser.

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

:::

How HTTP works

The HTTP protocol works on the client-server architecture. As a HTTP client, the browser sends all requests to the HTTP server, the WEB server, through URL.

Web servers include: Apache server, IIS server (Internet Information Services) and so on.

After receiving the request, the Web server sends response information to the client.

The default port number for HTTP is 80, but you can also change it to 8080 or another port.

There are three points to note for HTTP:

HTTP is connectionless: connectionless means limiting the processing of only one request per connection. After the server processes the customer's request and receives the customer's reply, it disconnects. Transmission time can be saved in this way.

HTTP is media independent: this means that any type of data can be sent over HTTP as long as the client and server know how to handle the data content. The client and server specify the appropriate MIME-type content type to be used.

Http:/ / www.iis7.com/b/plc/

HTTP is stateless: the HTTP protocol is stateless. Statelessness means that the protocol has no memory ability for transactions. The lack of state means that if the previous information is required for subsequent processing, it must be retransmitted, which may result in an increase in the amount of data transmitted per connection. On the other hand, the server responds faster when it does not need previous information.

:::

HTTP message structure

HTTP is a client / server-based architecture model that exchanges information through a reliable link and is a stateless request / response protocol.

An HTTP "client" is an application (Web browser or any other client) that connects to the server to send one or more HTTP requests to the server.

A HTTP "server" is also an application (usually a Web service, such as an Apache Web server or IIS server, etc.) by receiving requests from the client and sending HTTP response data to the client.

HTTP uses uniform resource identifiers (Uniform Resource Identifiers, URI) to transfer data and establish connections.

Once the connection is established, the data message is sent in a format similar to that used by Internet mail [RFC5322] and Multipurpose Internet Mail extension (MIME) [RFC2045].

:::

HTTP request method

According to the HTTP standard, HTTP requests can use a variety of request methods.

HTTP1.0 defines three request methods: GET, POST, and HEAD methods.

HTTP1.1 has added five request methods: OPTIONS, PUT, DELETE, TRACE and CONNECT methods.

1GET requests the specified page information and returns the entity body.

2HEAD is similar to a get request, except that there is no specific content in the returned response, which is used to get the header.

3POST submits data to the specified resource for processing requests (such as submitting a form or uploading a file). The data is contained in the request body. POST requests may result in the creation of new resources and / or modification of existing resources.

The data that 4PUT sends from the client to the server replaces the contents of the specified document.

5DELETE requests the server to delete the specified page.

The 6CONNECTHTTP/1.1 protocol is reserved for proxy servers that can change connections to pipelines.

7OPTIONS allows clients to view the performance of the server.

8TRACE echoes requests received by the server, mainly for testing or diagnosis.

:::

HTTP response header information

The HTTP request header provides information about the request, response, or other sending entity.

Response header description

Which request methods (such as GET, POST, etc.) are supported by the Allow server.

Content-Encoding

The Encode method of the document. The content type specified by the Content-Type header can be obtained only after decoding. Using gzip to compress documents can significantly reduce the download time of HTML documents. Java's GZIPOutputStream can easily do gzip compression, but only Netscape on Unix and IE 4 and IE 5 on Windows support it. Therefore, Servlet should check whether the browser supports gzip by looking at the Accept-Encoding header (that is, request.getHeader ("Accept-Encoding"), returning gzip-compressed HTML pages for browsers that support gzip, and normal pages for other browsers.

Content-Length

Represents the content length. This data is needed only if the browser uses a persistent HTTP connection. If you want to take advantage of persistent connections, you can write the output document to ByteArrayOutputStream, check its size when finished, put this value in the Content-Length header, and finally send the content through byteArrayStream.writeTo (response.getOutputStream ().

Content-Type

Indicates what MIME type the subsequent document belongs to. Servlet defaults to text/plain, but usually needs to be explicitly specified as text/html. Because Content-Type is often set up, HttpServletResponse provides a special method, setContentType.

Date's current GMT time. You can use setDateHeader to set this header to avoid the hassle of converting time formats.

When should Expires think that the document is out of date and stop caching it?

Last-Modified

The last change time of the document. The customer can provide a date through the If-Modified-Since request header, and the request will be treated as a conditional GET, and only documents whose change time is later than the specified time will be returned, otherwise a 304( Not Modified) status will be returned. Last-Modified can also be set using the setDateHeader method.

Location

Indicates where the customer should go to extract the document. Location is usually not set directly, but through the sendRedirect method of HttpServletResponse, which also sets the status code to 302.

Refresh

Indicates how much time, in seconds, the browser should refresh the document. In addition to refreshing the current document, you can also use setHeader ("Refresh", "5; URL= http://host/path")") to let the browser read the specified page.

Note that this functionality is usually achieved by setting the < META HTTP-EQUIV= "Refresh" CONTENT= "5 HTML URL = http://host/path" > in the HEAD area of the HTML page, because automatic refresh or redirection is important for HTML writers who cannot use CGI or Servlet. However, for Servlet, it is more convenient to set the Refresh header directly.

Note that the meaning of Refresh is "refresh this page or visit a specified page after N seconds", not "refresh this page or visit a specified page every N seconds". Therefore, a continuous refresh requires that one Refresh header be sent at a time, and sending a 204status code prevents the browser from continuing to refresh, whether using the refresh header or < META HTTP-EQUIV= "Refresh". >.

Note that the Refresh header is not part of the formal specification of HTTP 1.1, but is an extension, but is supported by both Netscape and IE.

Server

Server name. Servlet generally does not set this value, but is set by the Web server itself.

Set-Cookie

Sets the Cookie associated with the page. Instead of using response.setHeader ("Set-Cookie",...), Servlet should use the special method addCookie provided by HttpServletResponse. See the following discussion of Cookie settings.

WWW-Authenticate

What type of authorization information should the customer provide in the Authorization header? This header is required in a reply that contains a 401 (Unauthorized) status line. For example, response.setHeader ("WWW-Authenticate", "BASIC realm=\" executives\ "").

Note that Servlet generally does not handle this, but instead lets the Web server's special mechanism control access to password-protected pages (for example, .htaccess).

:::

HTTP status code

When a viewer visits a web page, the viewer's browser makes a request to the server where the web page is located. Before the browser receives and displays the web page, the server where the web page is located will return an information header (server header) containing the HTTP status code in response to the browser's request.

The English of HTTP status code is HTTP Status Code (status code).

Here are common HTTP status codes:

200-request succeeded

301-Resources (web pages, etc.) are permanently transferred to other URL

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

500-Internal server error

.

HTTP status code classification

The HTTP status code consists of three decimal digits. The first decimal number defines the type of the status code, and the last two digits have no classification function. There are 5 types of HTTP status codes:

HTTP status code classification

Classification description

1 request * message. The server receives a request and requires the requestor to continue with the operation.

2successfully * the operation was received and processed successfully

3 redirect, further action is required to complete the request

4error * client error, request containing syntax error or unable to complete the request

5error * Server error occurred while processing the request

List of HTTP status codes:

List of HTTP status codes

.

Description of status code in English and Chinese

100 Continue continues. The client should continue its request

101Switching Protocols switching protocol. The server switches the protocol according to the request of the client. You can only switch to a more advanced protocol, for example, to a new version of HTTP

200 OK request succeeded. Commonly used for GET and POST requests

201Created has been created. Successfully requested and created a new resource

202Accepted accepted. The request has been accepted but the processing has not been completed

203Non-Authoritative Information unauthorized information. The request was successful. But the returned meta information is not on the original server, but on a copy.

204No Content has no content. The server successfully processed but did not return content. If the web page is not updated, ensure that the browser continues to display the current document

205Reset Content resets the content. The server is processed successfully, and the user terminal (for example, browser) should reset the document view. The form field of the browser can be cleared by this return code

206Partial Content part of the content. The server successfully processed some GET requests

300Multiple Choices has a variety of options. The requested resource may include multiple locations, which can return a list of resource characteristics and addresses for user terminal (e. G. browser) selection

301Moved Permanently moves permanently. The requested resource has been permanently moved to the new URI, the returned information will include the new URI, and the browser will be automatically directed to the new URI. Any new requests in the future should be replaced by a new URI

302Found moves temporarily. Similar to 301. But resources are only temporarily moved. The client should continue to use the original URI

303See Other looks at other addresses. Similar to 301. Use GET and POST to request view

304Not Modified has not been modified. The requested resource has not been modified, and when the server returns this status code, no resource will be returned. The client usually caches the accessed resources, indicating that the client wants to return only those resources that have been modified after the specified date by providing a header information

305Use Proxy uses proxies. The requested resource must be accessed through an agent

306Unused's obsolete HTTP status code

307Temporary Redirect temporary redirection. Similar to 302. Request redirection using GET

The syntax of the 400Bad Request client request is incorrect and the server cannot understand it.

The 401Unauthorized request requires the user's authentication

402Payment Required reserved for future use

The 403Forbidden server understands the request of the requesting client, but refuses to execute the request

The 404Not Found server was unable to find the resource (web page) based on the client's request. Through this code, the website designer can set up a personality page that the resource you requested cannot be found.

Methods in 405Method Not Allowed client requests are prohibited

The 406Not Acceptable server cannot complete the request based on the content characteristics of the client request

The 407Proxy Authentication Required request requires the authentication of the agent, similar to 401, but the requestor should use the agent for authorization

The 408Request Time-out server waited too long for the request sent by the client, and timed out

When the 409Conflict server completes the client's PUT request, it is possible to return this code, and a conflict occurred when the server processed the request.

The resource requested by the 410Gone client no longer exists. 410 is different from 404, if the resource has been permanently deleted and can use 410 code, the website designer can specify the new location of the resource through 301 code.

The 411Length Required server cannot process the request information sent by the client without Content-Length

Prerequisite error for 412Precondition Failed client request information

413Request Entity Too Large rejected the request because the requested entity was too large for the server to process. To prevent continuous requests from the client, the server may close the connection. If only the server cannot process it temporarily, it will contain a Retry-After response message.

The URI of the 414Request-URI Too Large request is too long (the URI is usually the URL) and the server cannot process it.

The 415Unsupported Media Type server cannot process the media format that came with the request

Invalid scope of 416Requested range not satisfiable client request

The 417Expectation Failed server cannot satisfy the request header information of Expect

500Internal Server Error server internal error, unable to complete the request

The 501Not Implemented server does not support the requested function and cannot complete the request

The server where 502Bad Gateway acts as a gateway or proxy received an invalid request from the remote server

503Service Unavailable due to overloading or system maintenance, the server is temporarily unable to process client requests. The length of the delay can be included in the server's Retry-After header information

504Gateway Time-out acts as a gateway or proxy server and fails to obtain requests from the remote server in time

The 505HTTP Version not supported server does not support the version of the requested HTTP protocol and cannot complete the processing.

:::

HTTP content-type

Content-Type, content type, generally refers to the Content-Type that exists in the web page, which is used to define the type of network file and the coding of the web page, and to determine what form and encoding the browser will read the file. This is why you often see some Asp pages click on a file or a picture downloaded.

.

HTTP content-type comparison table

File extension Content-Type (Mime-Type) file extension Content-Type (Mime-Type)

. * (binary stream, do not know the download file type) application/octet-stream.tifimage/tiff

.001application / x-001.301application/x-301

.323text / h423.906application/x-906

. 907drawing/907.a11application/x-a11

.acpaudio / x-mei-aac.aiapplication/postscript

.aifaudio / aiff.aifcaudio/aiff

. aiffaudio/aiff.anvapplication/x-anv

.asatext / asa.asfvideo/x-ms-asf

.asptext / asp.asxvideo/x-ms-asf

.auaudio / basic.avivideo/avi

.awfapplication / vnd.adobe.workflow.biztext/xml

.bmpapplication / x-bmp.botapplication/x-bot

.c4tapplication / x-c4t.c90application/x-c90

.calapplication / x-cals.catapplication/vnd.ms-pki.seccat

.cdfapplication / x-netcdf.cdrapplication/x-cdr

.celapplication / x-cel.cerapplication/x-x509-ca-cert

.cg4application / x-g4.cgmapplication/x-cgm

. citapplication/x-cit.classjava/*

. cmltext/xml.cmpapplication/x-cmp

.cmxapplication / x-cmx.cotapplication/x-cot

.crlapplication / pkix-crl.crtapplication/x-x509-ca-cert

. csiapplication/x-csi.csstext/css

.cutapplication / x-cut.dbfapplication/x-dbf

.dbmapplication / x-dbm.dbxapplication/x-dbx

. dcdtext/xml.dcxapplication/x-dcx

.derapplication / x-x509-ca-cert.dgnapplication/x-dgn

.dibapplication / x-dib.dllapplication/x-msdownload

.docapplication / msword.dotapplication/msword

. drwapplication/x-drw.dtdtext/xml

. dwfModel/vnd.dwf.dwfapplication/x-dwf

.dwgapplication / x-dwg.dxbapplication/x-dxb

. dxfapplication/x-dxf.ednapplication/vnd.adobe.edn

. emfapplication/x-emf.emlmessage/rfc822

. enttext/xml.epiapplication/x-epi

. epsapplication/x-ps.epsapplication/postscript

.etdapplication / x-ebx.exeapplication/x-msdownload

.faximage / fax.fdfapplication/vnd.fdf

.fifapplication / fractals.fotext/xml

.frmapplication / x-frm.g4application/x-g4

.gbrapreplication / xmurgbr.applicationcontrol x-

. gifimage/gif.gl2application/x-gl2

.gp4application / x-gp4.hglapplication/x-hgl

.hmrapplication / x-hmr.hpgapplication/x-hpgl

.hplapplication / x-hpl.hqxapplication/mac-binhex40

. hrfapplication/x-hrf.htaapplication/hta

. htctext/x-component.htmtext/html

.htmltext / html.htttext/webviewhtml

. htxtext/html.icbapplication/x-icb

.icoimage / x-icon.icoapplication/x-ico

.iffapplication / x-iff.ig4application/x-g4

.igsapplication / x-igs.iiiapplication/x-iphone

.imgapplication / x-img.insapplication/x-internet-signup

.ispapplication / x-internet-signup.IVFvideo/x-ivf

.javajava / * .jfifimage / jpeg

. jpeimage/jpeg.jpeapplication/x-jpe

.jpegimage / jpeg.jpgimage/jpeg

.jpgapplication / x-jpg.jsapplication/x-javascript

.jsptext / html.la1audio/x-liquid-file

.larapplication / x-laplayer-reg.latexapplication/x-latex

.lavsaudio / x-liquid-secure.lbmapplication/x-lbm

.lmsffaudio / x-la-lms.lsapplication/x-javascript

.ltrapplication / x-ltr.m1vvideo/x-mpeg

. m2vvideo/x-mpeg.m3uaudio/mpegurl

. m4evideo/mpeg4.macapplication/x-mac

.manapplication / x-troff-man.mathtext/xml

. mdbapplication/msaccess.mdbapplication/x-mdb

.mfpapplication / x-shockwave-flash.mhtmessage/rfc822

. mhtmlmessage/rfc822.miapplication/x-mi

.midaudio / mid.midiaudio/mid

. milapplication/x-mil.mmltext/xml

.mndaudio / x-musicnet-download.mnsaudio/x-musicnet-stream

.mochaapplication / x-javascript.movievideo/x-sgi-movie

.mp1audio / mp1.mp2audio/mp2

.mp2vvideo / mpeg.mp3audio/mp3

. mp4video/mpeg4.mpavideo/x-mpg

.mpdapplication / vnd.ms-project.mpevideo/x-mpeg

.mpegvideo / mpg.mpgvideo/mpg

.mpgaaudio / rn-mpeg.mppapplication/vnd.ms-project

.mpsvideo / x-mpeg.mptapplication/vnd.ms-project

.mpvvideo / mpg.mpv2video/mpeg

.mpwapplication / vnd.ms-project.mpxapplication/vnd.ms-project

. mtxtext/xml.mxpapplication/x-mmxp

. netimage/pnetvue.nrfapplication/x-nrf

.nwsmessage / rfc822.odctext/x-ms-odc

. outapplication/x-out.p10application/pkcs10

.p12application / x-pkcs12.p7bapplication/x-pkcs7-certificates

.p7capplication / pkcs7-mime.p7mapplication/pkcs7-mime

.p7rapplication / x-pkcs7-certreqresp.p7sapplication/pkcs7-signature

.pc5application / x-pc5.pciapplication/x-pci

.pclapplication / x-pcl.pcxapplication/x-pcx

.pdfapplication / pdf.pdfapplication/pdf

. pdxapplication/vnd.adobe.pdx.pfxapplication/x-pkcs12

.pglapplication / x-pgl.picapplication/x-pic

.pkoapplication / vnd.ms-pki.pko.plapplication/x-perl

.plgtext / html.plsaudio/scpls

. pltapplication/x-plt.pngimage/png

.pngapplication / x-png.potapplication/vnd.ms-powerpoint

.ppaapplication / vnd.ms-powerpoint.ppmapplication/x-ppm

.ppsapplication / vnd.ms-powerpoint.pptapplication/vnd.ms-powerpoint

.pptapplication / x-ppt.prapplication/x-pr

.prfapplication / pics-rules.prnapplication/x-prn

.prtapplication / x-prt.psapplication/x-ps

. psapplication/postscript.ptnapplication/x-ptn

.pwzapplication / vnd.ms-powerpoint.r3ttext/vnd.rn-realtext3d

.raaudio / vnd.rn-realaudio.ramaudio/x-pn-realaudio

.rasapplication / x-ras.ratapplication/rat-file

. rdftext/xml.recapplication/vnd.rn-recording

.redapplication / x-red.rgbapplication/x-rgb

.rjsapplication / vnd.rn-realsystem-rjs.rjtapplication/vnd.rn-realsystem-rjt

.rlcapplication / x-rlc.rleapplication/x-rle

. rmapplication/vnd.rn-realmedia.rmfapplication/vnd.adobe.rmf

.rmiaudio / mid.rmjapplication/vnd.rn-realsystem-rmj

.rmmaudio / x-pn-realaudio.rmpapplication/vnd.rn-rn_music_package

.rmsapplication / vnd.rn-realmedia-secure.rmvbapplication/vnd.rn-realmedia-vbr

.rmxapplication / vnd.rn-realsystem-rmx.rnxapplication/vnd.rn-realplayer

.rpimage / vnd.rn-realpix.rpmaudio/x-pn-realaudio-plugin

.rsmlapplication / vnd.rn-rsml.rttext/vnd.rn-realtext

. rtfapplication/msword.rtfapplication/x-rtf

.rvvideo / vnd.rn-realvideo.samapplication/x-sam

. satapplication/x-sat.sdpapplication/sdp

.sdwapplication / x-sdw.sitapplication/x-stuffit

.slbapplication / x-slb.sldapplication/x-sld

. slkdrawing/x-slk.smiapplication/smil

. smilapplication/smil.smkapplication/x-smk

.sndaudio / basic.soltext/plain

.sortext / plain.spcapplication/x-pkcs7-certificates

.splapplication / futuresplash.spptext/xml

. ssmapplication/streamingmedia.sstapplication/vnd.ms-pki.certstore

. stlapplication/vnd.ms-pki.stl.stmtext/html

. styapplication/x-sty.svgtext/xml

.swfapplication / x-shockwave-flash.tdfapplication/x-tdf

.tg4application / x-tg4.tgaapplication/x-tga

. tifimage/tiff.tifapplication/x-tif

.tiffimage / tiff.tldtext/xml

.topdrawing / x-top.torrentapplication/x-bittorrent

.tsdtext / xml.txttext/plain

. uinapplication/x-icq.ulstext/iuls

.vcftext / x-vcard.vdaapplication/x-vda

.vdxapplication / vnd.visio.vmltext/xml

. vpgapplication/x-vpeg005.vsdapplication/vnd.visio

. vsdapplication/x-vsd.vssapplication/vnd.visio

. vstapplication/vnd.visio.vstapplication/x-vst

.vswapplication / vnd.visio.vsxapplication/vnd.visio

.vtxapplication / vnd.visio.vxmltext/xml

.wavaudio / wav.waxaudio/x-ms-wax

.wb1application / x-wb1.wb2application/x-wb2

. wb3application/x-wb3.wbmpimage/vnd.wap.wbmp

. wizapplication/msword.wk3application/x-wk3

.wk4application / x-wk4.wkqapplication/x-wkq

.wksapplication / x-wks.wmvideo/x-ms-wm

.wmaaudio / x-ms-wma.wmdapplication/x-ms-wmd

. wmfapplication/x-wmf.wmltext/vnd.wap.wml

.wmvvideo / x-ms-wmv.wmxvideo/x-ms-wmx

.wmzapplication / x-ms-wmz.wp6application/x-wp6

.wpdapplication / x-wpd.wpgapplication/x-wpg

.wplapplication / vnd.ms-wpl.wq1application/x-wq1

.wr1application / x-wr1.wriapplication/x-wri

.wrkapplication / x-wrk.wsapplication/x-ws

. ws2application/x-ws.wsctext/scriptlet

.wsdltext / xml.wvxvideo/x-ms-wvx

.xdpapplication / vnd.adobe.xdp.xdrtext/xml

.xfdapplication / vnd.adobe.xfd.xfdfapplication/vnd.adobe.xfdf

. xhtmltext/html.xlsapplication/vnd.ms-excel

.xlsapplication / x-xls.xlwapplication/x-xlw

.xmltext / xml.xplaudio/scpls

.xqtext / xml.xqltext/xml

.xquerytext / xml.xsdtext/xml

.xsltext / xml.xslttext/xml

. xwdapplication/x-xwd.x_bapplication/x-x_b

.sisapplication / vnd.symbian.install.sisxapplication/vnd.symbian.install

.x _ tapplication/x-x_t.ipaapplication/vnd.iphone

.apkapplication / vnd.android.package-archive.xapapplication/x-silverlight-app

This is the end of the introduction to "how HTTP works". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report