Vous êtes sur la page 1sur 4

We are hiring

HTTPRequests
Advertisements

PreviousPage

NextPage

AnHTTPclientsendsanHTTPrequesttoaserverintheformofarequestmessagewhichincludesfollowingformat:

ARequestline

Zeroormoreheader(General|Request|Entity)fieldsfollowedbyCRLF

Anemptyline(i.e.,alinewithnothingprecedingtheCRLF)
indicatingtheendoftheheaderfields

Optionallyamessagebody

ThefollowingsectionsexplaineachoftheentitiesusedinanHTTPrequestmessage.

RequestLine
TheRequestLinebeginswithamethodtoken,followedbytheRequestURIandtheprotocolversion,andendingwithCRLF.Theelementsare
separatedbyspaceSPcharacters.
RequestLine=MethodSPRequestURISPHTTPVersionCRLF

Let'sdiscusseachofthepartsmentionedintheRequestLine.

RequestMethod
The request method indicates the method to be performed on the resource identified by the given RequestURI. The method is case
sensitiveandshouldalwaysbementionedinuppercase.ThefollowingtablelistsallthesupportedmethodsinHTTP/1.1.
S.N.

MethodandDescription

GET

TheGETmethodisusedtoretrieveinformationfromthegivenserverusingagivenURI.RequestsusingGETshouldonlyretrieve
dataandshouldhavenoothereffectonthedata.
2

HEAD

SameasGET,butittransfersthestatuslineandtheheadersectiononly.
3

POST

APOSTrequestisusedtosenddatatotheserver,forexample,customerinformation,fileupload,etc.usingHTMLforms.
4

PUT

Replacesallthecurrentrepresentationsofthetargetresourcewiththeuploadedcontent.
5

DELETE

RemovesallthecurrentrepresentationsofthetargetresourcegivenbyURI.
6

CONNECT

EstablishesatunneltotheserveridentifiedbyagivenURI.
7

OPTIONS

Describethecommunicationoptionsforthetargetresource.
8

TRACE

Performsamessageloopbacktestalongwiththepathtothetargetresource.

RequestURI
The RequestURI is a Uniform Resource Identifier and identifies the resource upon which to apply the request. Following are the most
commonlyusedformstospecifyanURI:
RequestURI="*"|absoluteURI|abs_path|authority

S.N.

MethodandDescription

Theasterisk*isusedwhenanHTTPrequestdoesnotapplytoaparticularresource,buttotheserveritself,andisonlyallowedwhenthe
methoduseddoesnotnecessarilyapplytoaresource.Forexample:

OPTIONS*HTTP/1.1
2

TheabsoluteURIisusedwhenanHTTPrequestisbeingmadetoaproxy.Theproxyisrequestedtoforwardtherequestorservicefroma
validcache,andreturntheresponse.Forexample:

GEThttp://www.w3.org/pub/WWW/TheProject.htmlHTTP/1.1
3

ThemostcommonformofRequestURIisthatusedtoidentifyaresourceonanoriginserverorgateway.Forexample,aclientwishingto
retrievearesourcedirectlyfromtheoriginserverwouldcreateaTCPconnectiontoport80ofthehost"www.w3.org"andsendthefollowing
lines:

GET/pub/WWW/TheProject.htmlHTTP/1.1
Host:www.w3.org
NotethattheabsolutepathcannotbeemptyifnoneispresentintheoriginalURI,itMUSTbegivenas"/"(theserverroot).

RequestHeaderFields
We will study Generalheader and Entityheader in a separate chapter when we will learn HTTP header fields. For now, let's check what
Requestheaderfieldsare.
Therequestheaderfieldsallowtheclienttopassadditionalinformationabouttherequest,andabouttheclientitself,totheserver.These
fieldsactasrequestmodifiers.HereisalistofsomeimportantRequestheaderfieldsthatcanbeusedbasedontherequirement:
AcceptCharset
AcceptEncoding
AcceptLanguage
Authorization
Expect
From
Host
IfMatch
IfModifiedSince
IfNoneMatch
IfRange
IfUnmodifiedSince

MaxForwards
ProxyAuthorization
Range
Referer
TE
UserAgent
YoucanintroduceyourcustomfieldsincaseyouaregoingtowriteyourowncustomClientandWebServer.

ExamplesofRequestMessage
Nowlet'sputitalltogethertoformanHTTPrequesttofetchhello.htmpagefromthewebserverrunningontutorialspoint.com
GET/hello.htmHTTP/1.1
UserAgent:Mozilla/4.0(compatible;MSIE5.01;WindowsNT)
Host:www.tutorialspoint.com
AcceptLanguage:enus
AcceptEncoding:gzip,deflate
Connection:KeepAlive

HerewearenotsendinganyrequestdatatotheserverbecausewearefetchingaplainHTMLpagefromtheserver.Connectionisageneral
header,andtherestoftheheadersarerequestheaders.Thefollowingexampleshowshowtosendformdatatotheserverusingrequest
messagebody:
POST/cgibin/process.cgiHTTP/1.1
UserAgent:Mozilla/4.0(compatible;MSIE5.01;WindowsNT)
Host:www.tutorialspoint.com
ContentType:application/xwwwformurlencoded
ContentLength:length
AcceptLanguage:enus
AcceptEncoding:gzip,deflate
Connection:KeepAlive
licenseID=string&content=string&/paramsXML=string

HerethegivenURL/cgibin/process.cgiwillbeusedtoprocessthepasseddataandaccordingly,aresponsewillbereturned.Herecontent
typetellstheserverthatthepasseddataisasimplewebformdataandlengthwillbetheactuallengthofthedataputinthemessage
body.ThefollowingexampleshowshowyoucanpassplainXMLtoyourwebserver:
POST/cgibin/process.cgiHTTP/1.1
UserAgent:Mozilla/4.0(compatible;MSIE5.01;WindowsNT)
Host:www.tutorialspoint.com
ContentType:text/xml;charset=utf8
ContentLength:length
AcceptLanguage:enus
AcceptEncoding:gzip,deflate
Connection:KeepAlive
<?xmlversion="1.0"encoding="utf8"?>
<stringxmlns="http://clearforest.com/">string</string>

PreviousPage

NextPage
Advertisements

Write for us

FAQ's

Helping

Contact

Copyright 2016. All Rights Reserved.


Enter email for newsletter

go

Vous aimerez peut-être aussi