Anda di halaman 1dari 3

We are hiring

HTTPResponses
Advertisements

PreviousPage

NextPage

Afterreceivingandinterpretingarequestmessage,aserverrespondswithanHTTPresponsemessage:

AStatusline

Zeroormoreheader(General|Response|Entity)fieldsfollowedbyCRLF

Anemptyline(i.e.,alinewithnothingprecedingtheCRLF)
indicatingtheendoftheheaderfields

Optionallyamessagebody

ThefollowingsectionsexplaineachoftheentitiesusedinanHTTPresponsemessage.

MessageStatusLine
A StatusLine consists of the protocol version followed by a numeric status code and its associated textual phrase. The elements are
separatedbyspaceSPcharacters.
StatusLine=HTTPVersionSPStatusCodeSPReasonPhraseCRLF

HTTPVersion
AserversupportingHTTPversion1.1willreturnthefollowingversioninformation:
HTTPVersion=HTTP/1.1

StatusCode
TheStatusCodeelementisa3digitintegerwherefirstdigitoftheStatusCodedefinestheclassofresponseandthelasttwodigitsdonot
haveanycategorizationrole.Thereare5valuesforthefirstdigit:
S.N.

CodeandDescription

1xx:Informational

Itmeanstherequestwasreceivedandtheprocessiscontinuing.
2

2xx:Success

Itmeanstheactionwassuccessfullyreceived,understood,andaccepted.
3

3xx:Redirection

Itmeansfurtheractionmustbetakeninordertocompletetherequest.
4

4xx:ClientError

Itmeanstherequestcontainsincorrectsyntaxorcannotbefulfilled.
5

5xx:ServerError

Itmeanstheserverfailedtofulfillanapparentlyvalidrequest.

HTTPstatuscodesareextensibleandHTTPapplicationsarenotrequiredtounderstandthemeaningofallregisteredstatuscodes.Alistofall
thestatuscodeshasbeengiveninaseparatechapterforyourreference.

ResponseHeaderFields
We will study Generalheader and Entityheader in a separate chapter when we will learn HTTP header fields. For now, let's check what
Responseheaderfieldsare.
The responseheader fields allow the server to pass additional information about the response which cannot be placed in the Status Line.
TheseheaderfieldsgiveinformationabouttheserverandaboutfurtheraccesstotheresourceidentifiedbytheRequestURI.
AcceptRanges
Age
ETag
Location
ProxyAuthenticate
RetryAfter
Server
Vary
WWWAuthenticate

YoucanintroduceyourcustomfieldsincaseyouaregoingtowriteyourowncustomWebClientandServer.

ExamplesofResponseMessage
Now let's put it all together to form an HTTP response for a request to fetch the hello.htm page from the web server running on
tutorialspoint.com
HTTP/1.1200OK
Date:Mon,27Jul200912:28:53GMT
Server:Apache/2.2.14(Win32)
LastModified:Wed,22Jul200919:15:56GMT
ContentLength:88
ContentType:text/html
Connection:Closed

<html>
<body>
<h1>Hello,World!</h1>
</body>
</html>

ThefollowingexampleshowsanHTTPresponsemessagedisplayingerrorconditionwhenthewebservercouldnotfindtherequestedpage:
HTTP/1.1404NotFound
Date:Sun,18Oct201210:36:20GMT
Server:Apache/2.2.14(Win32)
ContentLength:230
Connection:Closed
ContentType:text/html;charset=iso88591

<!DOCTYPEHTMLPUBLIC"//IETF//DTDHTML2.0//EN">
<html>
<head>
<title>404NotFound</title>
</head>
<body>
<h1>NotFound</h1>
<p>TherequestedURL/t.htmlwasnotfoundonthisserver.</p>
</body>
</html>

FollowingisanexampleofHTTPresponsemessageshowingerrorconditionwhenthewebserverencounteredawrongHTTPversioninthe
givenHTTPrequest:
HTTP/1.1400BadRequest
Date:Sun,18Oct201210:36:20GMT
Server:Apache/2.2.14(Win32)
ContentLength:230
ContentType:text/html;charset=iso88591
Connection:Closed

<!DOCTYPEHTMLPUBLIC"//IETF//DTDHTML2.0//EN">
<html>
<head>
<title>400BadRequest</title>
</head>
<body>
<h1>BadRequest</h1>
<p>Yourbrowsersentarequestthatthisservercouldnotunderstand.</p>
<p>Therequestlinecontainedinvalidcharactersfollowingtheprotocolstring.</p>
</body>
</html>

PreviousPage

NextPage
Advertisements

FreeIPv6
Certification
Getstartedinminutes!Become
anIPv6Sage

EnterSite

Write for us

FAQ's

Helping

Contact

Copyright 2016. All Rights Reserved.


Enter email for newsletter

go

Anda mungkin juga menyukai