Sie sind auf Seite 1von 5

8/22/2014 HTTP Methods

http://www.tutorialspoint.com/cgi-bin/printpage.cgi 1/5
http://www.tutorialspoint.com/http/http_methods.htm Copyrighttutorialspoint.com
HTTPMETHODS
ThesetofcommonmethodsforHTTP/1.1isdefinedbelowandthissetcanbeexpandedbasedonrequirement.
Thesemethodnamesarecasesensitiveandtheymustbeusedinuppercase.
S.N. MethodandDescription
1 GET
TheGETmethodisusedtoretrieveinformationfromthegivenserverusingagivenURI.Requests
usingGETshouldonlyretrievedataandshouldhavenoothereffectonthedata.
2 HEAD
SameasGET,butonlytransferthestatuslineandheadersection.
3 POST
APOSTrequestisusedtosenddatatotheserver,forexamplecustomerinformation,fileuploadetc
usingHTMLforms.
4 PUT
Replaceallcurrentrepresentationsofthetargetresourcewiththeuploadedcontent.
5 DELETE
RemoveallcurrentrepresentationsofthetargetresourcegivenbyURI.
6 CONNECT
EstablishatunneltotheserveridentifiedbyagivenURI.
7 OPTIONS
Describethecommunicationoptionsforthetargetresource.
8 TRACE
Performamessageloopbacktestalongthepathtothetargetresource.
GETMethod
AGETrequestretrievesdatafromawebserverbyspecifyingparametersintheURLportionoftherequest.
Thisisthemainmethodusedfordocumentretrieval.FollowingisasimpleexamplewhichmakesuseofGET
methodtofetchhello.htm:
GET /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
FollowingwillbeaserverresponseagainsttheaboveGETrequest:
8/22/2014 HTTP Methods
http://www.tutorialspoint.com/cgi-bin/printpage.cgi 2/5
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Vary: Authorization,Accept
Accept-Ranges: bytes
Content-Length: 88
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
HEADMethod
TheHEADmethodisfunctionallylikeGET,exceptthattheserverreplieswitharesponselineandheaders,but
noentitybody.FollowingisasimpleexamplewhichmakesuseofHEADmethodtofetchheaderinformation
abouthello.htm:
HEAD /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
FollowingwillbeaserverresponseagainsttheaboveGETrequest:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Vary: Authorization,Accept
Accept-Ranges: bytes
Content-Length: 88
Content-Type: text/html
Connection: Closed
Youcannoticethathereserverdoesnotsendanydataafterheader.
POSTMethod
ThePOSTmethodisusedwhenyouwanttosendsomedatatotheserver,forexamplefileupdate,formdata
etc.FollowingisasimpleexamplewhichmakesuseofPOSTmethodtosendaformdatatotheserverwhich
willbeprocessedbyaprocess.cgiandfinallyaresponsewillbereturned:
POST /cgi-bin/process.cgi HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Content-Type: text/xml; charset=utf-8
Content-Length: 88
Accept-Language: en-us
8/22/2014 HTTP Methods
http://www.tutorialspoint.com/cgi-bin/printpage.cgi 3/5
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://clearforest.com/">string</string>
Serversidescriptprocess.cgiprocessthepasseddataandsendfollowingresponse:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
ETag: "34aa387-d-1568eb00"
Vary: Authorization,Accept
Accept-Ranges: bytes
Content-Length: 88
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Request Processed Successfully</h1>
</body>
</html>
PUTMethod
ThePUTmethodisusedtorequesttheservertostoretheincludedentitybodyatalocationspecifiedbythe
givenURL.Thefollowingexamplerequestservertosavethegivenentityboyinhello.htmattherootofthe
server:
PUT /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Connection: Keep-Alive
Content-type: text/html
Content-Length: 182
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
Theserverwillstoregivenentitybodyinhello.htmfileandwillsendfollowingresponsebacktotheclient:
HTTP/1.1 201 Created
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Content-type: text/html
Content-length: 30
Connection: Closed
<html>
<body>
<h1>The file was created.</h1>
</body>
8/22/2014 HTTP Methods
http://www.tutorialspoint.com/cgi-bin/printpage.cgi 4/5
</html>
DELETEMethod
TheDELETEmethodisusedtorequesttheservertodeletefileatalocationspecifiedbythegivenURL.The
followingexamplerequestservertodeletethegivenfilehello.htmattherootoftheserver:
DELETE /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.tutorialspoint.com
Accept-Language: en-us
Connection: Keep-Alive
Theserverwilldeletementionedfilehello.htmandwillsendfollowingresponsebacktotheclient:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Content-type: text/html
Content-length: 30
Connection: Closed
<html>
<body>
<h1>URL deleted.</h1>
</body>
</html>
CONNECTMethod
TheCONNECTmethodisusedbytheclienttoestablishanetworkconnectiontoawebserveroverHTTP.The
followingexamplerequestaconnectionwithawebserverrunningonhosttutorialspoint.com:
CONNECT www.tutorialspoint.com HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Theconnectionisestablishedwiththeserverandfollowingresponseissentbacktotheclient:
HTTP/1.1 200 Connection established
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
OPTIONSMethod
TheOPTIONSmethodisusedbytheclienttofindoutwhataretheHTTPmethodsandotheroptionssupported
byawebserver.TheclientcanspecifyaURLfortheOPTIONSmethod,oranasterisk(*)torefertotheentire
server.Thefollowingexamplerequestalistofmethodssupportedbyawebserverrunningon
tutorialspoint.com:
OPTIONS * HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Theserverwillsendinformationbasedonthecurrentconfigurationoftheserver,forexample:
8/22/2014 HTTP Methods
http://www.tutorialspoint.com/cgi-bin/printpage.cgi 5/5
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Type: httpd/unix-directory
TRACEMethod
TheTRACEmethodisusedtoeachothecontentsofanHTTPRequestbacktotherequesterwhichcanbeused
fordebuggingpurposeatthetimeofdevelopment.ThefollowingexampleshowstheusageofTRACEmethod:
TRACE / HTTP/1.1
Host: www.tutorialspoint.com
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Theserverwillsendfollowingmessageinresponseoftheaboverequest:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Connection: close
Content-Type: message/http
Content-Length: 39
TRACE / HTTP/1.1
Host: www.tutorialspoint.com
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)

Das könnte Ihnen auch gefallen