Tải bản đầy đủ - 0 (trang)
Chapter 32. The Hypertext Transfer Protocol

Chapter 32. The Hypertext Transfer Protocol

Tải bản đầy đủ - 0trang

created.HTTP,likeotherapplicationprotocols,istransmittedon

thenetworkusingTCP/IPastheunderlyingprotocoltoensurea

timely,reliabletransport.

YetHTTPistheprotocolthatisplacedbetweenHTMLand

TCP/IP.KeepinmindthatHTMLisjustalanguageusedfor

creatingWebpages.HTTPisusedtotransferthesepagesto

endusers,andHTTPistransportedacrosstheInternetusing

TCP/IP.

Thischapterisnotgoingtohelpyoulearnthemanyversionsof

HTML,orotherprogramminglanguages(suchasJavaandC#).

Instead,youwilllearnaboutHTTP.



Note

HTTPiscurrentlydefinedbyversion1.1.Inthis

chapteryouwilllearnaboutsomeofthehistoryof

HTTP,includingtheconceptspresentedbythe

originalversionaswellasHTTPv.1.1.







TheBeginningofHTTP

ThebeginningofHTTPstartedwithavendor-supported

consortiumcalledtheWorldWideWebconsortum(W3C).

AlthoughWC3wasresponsibleforthecreationofmanyInternet

Webstandards,themostprominentaretheHypertextTransfer

ProtocolandotherInternetstandards.In1989,CERN(theHigh

EnergyParticlePhysicsLaboratoryinGeneva,Switzerland)

scientistDr.TimBerners-Leedevelopedthefirstversionof

HTTP,whichwastohelptheWorldWideWebgainpopularity

andgrowdramatically.Insteadoftheusualemail,FTP,and

otherutilitiesthattheInternetwasusingatthattime,thenew

HTTPallowedaneasierwaytoshareinformationquickly.

BecauseofthetimeinvolvedinongoingdevelopmentofHTTP,

CERNpartneredwithINRIA(theFrenchNationalInstituteof

ResearchforComputerScienceandControl).Today,manyother

organizationsareinvolvedincontinuingthedevelopmentof

HTTP,suchastheMassachusettsInstituteofTechnology(MIT)

LaboratoryforComputerScience,andtheInternetEngineering

TaskForce(IETF).Thus,youcanfindRFC(Requestfor

Comments)documentsontheWebaboutcurrentandfuture

developmentoftheprotocol.



Note

TheW3Cisnotagovernmentorganization.Itisan

industry-supportedconsortiumwhosepurposeisto

promotestandardsfortheWeb,including

interoperabilityamongWebprotocolsandsoftware.

W3Cdoeshelptoestablishstandardstoachievethis

goal.



Currentproposed,informational,andstandardsRFCsinclude

thefollowing:

RFC1945,"HypertextTransferProtocolHTTP/1.0."Written

in1996byBerners-Lee,R.Fielding,andH.Frystyk,this

informationalRFCwasthebeginningofthestandardization

processwithintheInternetcommunity.

RFC2145,"UseandInterpretationofHTTPVersion

Numbers."ThisisalsoaninformationalRFCthatfurther

specifieshowversionnumbersoftheHTTPprotocolshould

beused.

RFC2519,"HTTPExtensionsforDistributedAuthoring

WEBDAV."Thisisaproposedstandard.

RFC2831,"UsingDigestAuthenticationasaSASL

Mechanism."ThisRFCisalsoaproposedstandard,andit

discussesusingSASL(SimpleAuthenticationandSecurity

Layer)toprovidesupportforconnection-basedprotocols,

suchasHTTP.

RFC2935,"InternetOpenTradingProtocol(IOTP)HTTP

Supplement."IOTPmessagesaretransportedasXML

(ExtensibleMarkupLanguage)documents.Thegoalofthis

RFCistoensurethatXMLdocumentsaresuccessfully

exchangedbetweenthepartiesinvolvedinthe

communication.

RFC3229,"DeltaEncodinginHTTP."ThisRFCproposesa

methodforconservingvaluablebandwidthontheNetby

downloadingonlychangestocachedWebpages.Rather

thansendingtheentiredatatransportedbyHTTP,only

changes,calleddeltaencoding,aresent.



RFC3230,"InstanceDigestsinHTTP."Thisisanother

proposedstandardforHTTPversion1.1thatdescribesthe

useofMD5(MessageDigestv.5)toensurereliable

transportofdatacarriedbyHTTP.MD5,createdbyRonald

L.RivestofMIT,isthethirdversionofthisencryption

technique.ThepreviousversionswereMD2andMD4.

RFC3310,"HypertextTransferProtocol(HTTP)Digest

AuthenticationUsingAuthenticationandKeyAgreement

(AKA)."ThisisanotherinformationalRFCdiscussing

authenticationforusewithHTTP.

TheprecedingRFCs(andothersreferencedintheseRFCs)are

recommendedreadingforthosewhowanttopursuenewer

developmentsthatmaybecomepartoftheHTTPprotocolinthe

nearfuture.



DefiningHTTP

HTTPwascreatedtoenableHTTPtotransporthypertext

throughtheInternet.Hypertexttechnologywasfirstdeveloped

byTedNelsonandwasofficiallyknownthenastheXanadu

system.Xanaduwasamethodofcreatingdocumentsonthe

Web,usingoneormoreauthors.Oneofthemainfeatureswas

theuseofhyperlinks.AlthoughNelson'soriginalideasnever

caughton,theywereinstrumentalinthedevelopmentofHTML

aswellasHTTP.

HTTPisbasicallyaprotocolthatenablesthetransferoftext,

images,andotherdatabetweencomputersontheWeb.

AlthoughHTMLmightseemtobeaprotocol,itisnot.Without

HTTP,orasimilarprotocol,therewouldbenoHTMLpageson

theInternet.HTTPreliesontheunderlyingTCP/IPprotocolsfor

transportthroughtheInternet,andthusHTTPcanbe

consideredanapplicationprotocol.

AlthoughHTTPhasbeeninuseontheNetsince1990,inRFC

1945,firstpublishedin1996,theHypertextTransferProtocol

(version1,commonlyreferredtoasHTML/1)wasdescribedby

Berners-Leeandotherauthors.HTTPisastatelessprotocol,

similartoIP.Itisalsoanapplicationprotocolbecauseituses

TCP/IPasatransportmechanism.Thetermstatelessmeans

thatthereisnorequirementforasession,suchaswithaTCP

sessioninwhichparametersareexchangedbetweenthe

endpointsofaconnection(thesetupphase)beforedata

exchangescanoccur.Instead,arequestissenttoaservervia

theNet,andprovidedthatnoerrorsoccur,aresponseissent

back.



HTTPMechanics



Aspreviouslyindicated,HTTPisaclient/serverprotocol.The

clientapplication(suchasabrowser)sendsarequesttothe

serverthathoststheinformationtheuserneeds(typicallya

Webpage).Theserversendsbackaresponse.Thedataobject

theclientrequestsisidentifiedbyaUniformResourceIdentifier

(URI),suchasaUniformResourceLocator(URL).Bothofthese

aredescribedlaterinthischapter.

ThedataobjectisencapsulatedbyHTTPandreturnedtothe

requestor.AlthoughHTTPcommandsareterminatedusingthe

combinationof(carriagereturn/linefeed),theobject

encapsulatedinHTTP(thepayload)doesnothavetoadhereto

thisrule.Instead,thepayload(referredtoastheentity-bodyin

HTTPterminology)isdeterminedbythetypeofinformation

beingtransferred.Forexample,plainASCIItextmayusethe

combinationtomarktheendofarecord,whereas

Unix/Linuxsystemsusejustthecharacter.Andgraphics

filescanbecomposedinmanydifferentformats,fromGIFto

JPEG,amongothers.Theimportantthingtorememberisthat

theentity-bodycarriedbyHTTPisindependentoftheHTTP

protocol.

Mostallbrowserstodayalsomaintainacache,whichstores

recentlyrequestedpages.Atthetopofyourbrowser,there

shouldbeabuttonyoucanusetorefreshapagesendarequest

totheservertogetthemostup-to-dateversionofapage

insteadofonestoredinthecache.Somepagesaremarkedby

theserversothattheywillnotbestoredintherequestor's

cache.ThesepagesarerefreshedfromtheHTTPservereach

timeyoureferencethedatasource.



HTTPHeaderFields

HTTPheaderfields(nottobeconfusedwithheadersthatmay

existintheentity-body,orpayloadbeingcarriedbyHTTP)can

varydependingontheversionofHTTP,aswellasthecontent



beingcarried.EachHTTPheaderfieldismadeupofaname

followedbythecoloncharacter(:),thenaspace,andfinallythe

valuefortheparticularheader.Namesforfieldsarecase

insensitive.

SomeexamplesofHTTPheadersincludeacontenttypefieldto

identifytheentity-body,aswellasthelengthofthedata.

Anotherexample,whichcanaffectthetimethecontentfroma

requestiscached,istheExpiresfield.Browsersthat

recommendthisfieldwillnotdisplayWebpages/datatothe

userfromthecacheaftertheinformationhasexpired.Instead,

anewrequestwillbesenttotheHTTPserver.

Manyotherheaderfieldsarealsodefined,andyoucanfindout

aboutthembyreadingtheRFCslistedatthebeginningofthis

chapter.Here,justthebasicsarepresented,aswellasthe

syntaxforformingheaderfields.

AlthoughmostusersarefamiliarwithusingtheAddressfieldin

abrowsertoenteraURL,mostdonotknowwhataURLis.







URLs,URIs,andURNs

MostanyuseroftheInternetunderstandsthatyouneedtoput

aURL(UniformResourceLocator)intheAddressfieldofa

browsertosendarequesttoaWebserver.However,theURLis

onlyoneofmanyURIs(UniformResourceIdentifiersalthoughin

theoriginalHTTPRFC,URLwastermedUniversalResource

Identifier).YouspecifyaURLbyusingtheprefixhttp://inthe

addressspaceofyourbrowser.However,otherURIs

(identifiers)canbeused,suchasftp://ifyouwanttousea

browsertodownloadfilesfromaremoteserver.

TheimportantthingtorememberhereisthatURLsarejusta

subsetofURIs,andtherearemanyURIs.However,URLsare

probablythemostwidelyusedURIs.

RFC1630,writtenbyBerners-Lee,alsodiscussesURNs

(UniformResourceNames),whichrefertoanamespacethatis

morepersistentthanobjectsthatrefertoURLs.

Althoughthisdefinitionisnotconsideredtobeastandard,

Berners-LeedescribestheURIsyntaxthisway:

Itshouldbeextensiblesothatnewnamingschemescanbe

addedlaterasdeterminedbyhowtheWebevolves.

Thesyntaxshouldbecompletesothatanynamingscheme

canbeencodedinaURI.

TheURIshouldbe"printable,"meaningthatanyURIshould

beabletobedescribedusing7-bitASCIIcharacters.

Toprovidefortheextensiblecharacteristicofthesyntax,this

RFCassumedthatnewURIprefixes(http://,ftp://,andsoon)

canbeanarbitrarystringofcharacters,butalsoshouldbe



registeredbysomeauthoritytoensureuniformityontheWeb.

ThetextthatfollowstheprefixedURIdesignatorisdependent

ontheprefix.Forexample,http://wouldassumethataWeb

serveraddressfollowstheprefix.Forftp://,thetextfollowing

thisprefixshouldbeinconformancewithFTPconventions,in

ordertospecifyanaddressandfiletobedownloaded.

ThisRFCalsorequiresthatacoloncharacter(:)followthe

prefix.Theuseofslashes(//)isusedtoindicateahierarchyof

somesort,suchasapaththroughanamingconventionthat

leadstotheeventuallocationofinformation,ortheobject

soughtbytheprefix.



Note

Theuseoftheslashcharactershouldnotbe

confusedwiththecharacterusedinsomeoperating

systemsasadirectoryhierarchyspecification.There

isnorelationshipbetweenthetextfollowingaURI

andthetextthatfollows,evenifitcontainsthe

slashcharacter.



Becausesomecharacters(suchasthespacecharacter)can

causeconflicts(especiallywhenURIsareusedinemail

messages,andaresolongthatthetextiswrapped),anescape

characterisused.Thepercentsign(%)isusedastheescape

character.Thischaractershouldbeusedforonlythispurpose,

andnothingelse.

Othercharacters,suchasthehashcharacter(#)andthe

questionmark(?),alsoserveaparticularpurpose.The#

characterisusedtoseparatetheobjectofaURIfroman

identifierrelatedtothespecificURI.The?characterisusedto

separatetheURIfromanobjectthatcanbequeried.Inother



words,the?meansthatthetextthatfollowsitisusedtopass

datatoaquerybasedontheoriginalobjectthatisreferenced

bytheURI.YouwillseethischaracterappearinmanyURLs

whenyoureferenceaWebsite.Thischaracterisusedinmany

URLsafteryouentertext(inasearchengine,forexample)to

createthefinalURLthatisusedtoapplythesyntaxofyour

querytotheobjectyoureferencedintheURLthatyouentered.

YoucantrythisbyvisitingjustaboutanymajorWebsite,such

asMicrosoft,orasearchengine.WatchtheAddressfieldon

yourbrowserandyouwillseealongerstringofwhatappears

tobeameaninglessstringofcharacters.Itis,however,the

syntaxthatthesearchengine(orotherWebsite)usestoapply

yourquerytofindtheinformationyouarelookingfor.



Note

AlthoughtheuseofspacesinaURLorURIis

discouraged,theplussign(+)isusedtoindicatea

space.Ifyouwanttouse+intheURIorURL,it

mustbeescaped(inotherwords,thetextthat

followstheescapecharactershouldbeinterpreted

literally).Theescape,asexplainedinthemaintext,

isthepercentcharacter(%).Toidentifyaspecific

character,youwouldfirstusetheescapecharacter

followedbytheASCIIhexvalueforthecharacter.A

literalplussign(ASCIIcode2B)wouldthereforebe

representedas%2B.



Otherreservedcharacters,whichcanbeusedbyanyURIand

whichapplytothesyntaxofthoseURIs,aretheasterisk(*)

characterandtheexclamationmark(!).Inotherwords,these

charactersdonotmeanthesamethingforallURIs.EachURI

canusethesecharactersforameaningspecifictotheparticular



URI.

Ifthissoundsconfusing,justgotoasearchengineandlookat

thestringofcharactersthatfollowsyourquery.InFigure32.1

youcanseethatenteringtheURLwww.google.combringsup

theinitialquerypageforthissearchengine.



Figure32.1.YoucanenteraURLtobringupa

particularWebpage,suchasasearchengine.



[Viewfullsizeimage]



Yetwhenyouentertextintothissearchengine'sSearchfield,

andclickontheSearchbutton,theURLintheAddressfieldof

yourbrowseristranslatedtoaquerythatthesearchengine

usestolocateresourcesrelatedtoyourquery,asshownin

Figure32.2.



Figure32.2.Yourquerycanchangeafteryou



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 32. The Hypertext Transfer Protocol

Tải bản đầy đủ ngay(0 tr)

×