0% found this document useful (0 votes)
75 views12 pages

Messages For HTML Pages, Images, Scripts and Styles Sheets. Web Servers

The document provides an overview of the Hypertext Transfer Protocol (HTTP) including details on HTTP request and response messages, headers, status codes, errors, caching and methods. Some key points: - HTTP is the client-server protocol used on the World Wide Web that allows browsers to request web pages and servers to return responses. Requests use the GET method and responses contain HTML, images and other files. - Requests and responses contain a start line (URL and version), headers (name-value pairs) and an optional message body. Common headers provide info on encodings, caching, content types and more. - Status codes in responses indicate if the request succeeded (2xx), was redirected (3xx)
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views12 pages

Messages For HTML Pages, Images, Scripts and Styles Sheets. Web Servers

The document provides an overview of the Hypertext Transfer Protocol (HTTP) including details on HTTP request and response messages, headers, status codes, errors, caching and methods. Some key points: - HTTP is the client-server protocol used on the World Wide Web that allows browsers to request web pages and servers to return responses. Requests use the GET method and responses contain HTML, images and other files. - Requests and responses contain a start line (URL and version), headers (name-value pairs) and an optional message body. Common headers provide info on encodings, caching, content types and more. - Status codes in responses indicate if the request succeeded (2xx), was redirected (3xx)
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

1.

Introduction

The Hyper Text Transfer Protocol (HTTP) is the client-server network


protocol that has been in use by the World-Wide Web since 1990.
Whenever you surf the web, your browser will be sending HTTP request
messages for HTML pages, images, scripts and styles sheets. Web servers
handle these requests by returning response messages that contain the
requested resource.

1.1 HTTP Request Message

The HTTP request message has a simple text based structure. For
example, here is the the request message sent by Internet Explorer (IE) for
this web page:

GET /httpgallery/introduction/ HTTP/1.1

Accept: */*

Accept-Language: en-gb

Accept-Encoding: gzip, deflate

User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0;


rv:11.0) like Gecko

Host: www.httpwatch.com

Connection: Keep-Alive

The first line of the message, known as the request line, contains:

 The HTTP method. (See 6. HTTP Methods for more information)

 The relative URL of the resource or a full URL if you are using an HTTP
proxy

 The version of HTTP that is being used. Most modern HTTP clients and
servers will use HTTP version 1.1 as defined in RFC 2616.

The rest of the message consists of a set of name/value pairs, known


as headers (See 2. HTTP Headers). HTTP clients use header values to
control how the request is processed by the server. For example,
the Accept-Encoding header indicates that the browser can handle
content compressed using the gzip or deflate algorithms (see 8. HTTP
Compression).

1.2 HTTP Response Message

The web server's response message has a similar structure, but is followed
by the contents of the HTML page:

HTTP/1.1 200 OK

Server: Microsoft-IIS/8.0

Date: Mon, 04 Jan 2015 12:04:43 GMT

X-Powered-By: ASP.NET

X-AspNet-Version: 4.0.30319

Cache-Control: no-cache, no-store

Expires: -1

Content-Type: text/html; charset=utf-8

Content-Length: 14990

<!DOCTYPE html> <html>...

The first line, or status line, returns a status code from the server that
indicates whether the request was successful (see 3. Status codes and
errors). The value 200 is returned if the request was processed correctly
and content is being returned to the client.

The next eight lines of text contain header values that describe the data
and the way in which it is being returned to the client. For
example, Content-Type has the value text/html because the page is in
HTML format. The response headers are terminated with a double CRLF
(carriage return, line feed) and are followed by the contents of the
requested resource.
Images are not directly embedded into web pages. Instead, they are
specified as separate resources using HTML <img> tags:

<img src="images/logo.gif" width="50" height="50">

Whenever the browser encounters an <img> tag, it checks to see if it has a


valid copy of the image either loaded in memory or saved in its cache. If no
suitable match is found, it sends out another HTTP request to retrieve it.
This means that a web page will usually generate multiple HTTP requests;
one for the HTML page and one for each of the images.

Example 1

Clicking the Refresh button will redisplay this web page by sending HTTP
requests to download the HTML of the page and its associated styles sheets and
images.

2. HTTP Headers

Headers are name/value pairs that appear in both request and response

messages. The name of the header is separated from the value by a single

colon. For example, this line in a request message:

User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0;


rv:11.0) like Gecko

provides a header called User-Agent whose value is Mozilla/4.0

(compatible; MSIE 6.0; Windows NT 5.1). The purpose of this particular

header is to supply the web server with information about the type of
browser making the request. A complete definition of this and other

commonly encountered HTTP headers can be found in the HTTP 1.1

specification.

Some web applications use custom headers to add comments or

annotations to an HTTP message. The convention is to prefix the header

name with X- to indicate that it is non-standard. In the previous example,

the HTTP response message from this web server set an X-AspNet-

Version header to indicate which version of ASP.NET it is running.

Example 2

Clicking the Get Current Time button requests an updated copy of the following

image:

Using HttpWatch with Example 2

To view the HTTP headers discussed on this page:


1. Open HttpWatch by right clicking on the web page and

selecting HttpWatch from the context menu

2. Click on Record to start logging requests in HttpWatch

3. Click on the Get Current Time button above

4. Select the single entry displayed and go to

the Headers tab

The Headers tab will show two lists of headers; the one on the left

is for the request message and the one on the right for the response

message.
2.1 Request Headers

HTTP clients use headers in the request message to identify themselves

and control how content is returned. If you are using IE, you will have seen

the following headers sent with the request in Example 2:

Accept:*/*

This header indicates that the browser will accept all types of content.
Accept-Language: en-gb

The browser prefers British English content.

Accept-Encoding: gzip, deflate

The browser can handle gzip or deflate compressed content

Connection: Keep-Alive

The browser is requesting the use of persistent TCP connections.

Host: www.httpwatch.com

HTTP/1.1 requires that the host name is supplied with every request so that

multiple domains can be hosted on a single IP address.


Referer: http://www.httpwatch.com/httpgallery/headers/

This is supplied by the browser to indicate if the current request was the

result of a link from another web page. The server may use this information

to gather usage statistics or to track which web sites have links to a page.

User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0;


rv:11.0) like Gecko

This identifies the browser is Internet Explorer Version 11 running on

Windows 8.1 x64

2.2 Response Headers

HTTP servers use headers in the response message to specify how

content is being returned and how it should be handled. If you are using IE,

you will have seen the following headers returned with the image in

Example 2:
Cache-Control: no-cache

This header indicates whether the resource may be cached by the browser

or any immediate caches. The value no-cache disables all caching.

(See 5. Caching for more information)

Content-Length: 2748

This header contains the length in bytes of the resource (i.e. the gif image)

that follows the headers.

Content-Type: image/gif

The content is in GIF format.

Date: Wed, 4 Oct 2004 12:00:00 GMT

This is the current date and time on the web server.


Expires: -1

The Expires header specifies when the content should be considered to be

out of date. The value -1 indicates that the content expires immediately and

would have to be re-requested before being displayed again.

Pragma: no-cache

The browser may be connecting to the server via HTTP/1.0 proxies or

caches, that do not support theCache-Control header.

Setting Pragma to no-cache header prevents HTTP/1.0 caches from

storing the content.

Server: Microsoft-IIS/6.0

The web server is an IIS 6 web server.

X-AspNet-Version: 4.0.30319
The web server is running ASP.NET 4.0

X-Powered-By: ASP.NET

3. HTTP Status Codes and Errors

An HTTP request can fail because of a network error or because of


problems encountered while the request is executing on the web server.

3.1 Network Errors

If a network error occurs while transmitting a request message, error


information is available from the underlying network component; e.g.
Windows Sockets or WinInet. Monitoring tools like HttpWatch can display
error codes for situations such as:

1. The host name could not be converted into an IP address, perhaps


because an invalid host name was used or because no DNS lookup
service is available.

2. The browser could not connect to the web server. This may happen if
the web server is not running or is listening on the wrong port.

3. The network connection may be broken while transmitting the request


message, perhaps because a physical network connection has been
interrupted, e.g. a network cable has been unplugged.

3.2 Status Codes

HTTP status codes are returned by web servers to describe if and how a
request was processed. The codes are grouped by the first digit:
1xx - Informational

Any code starting with '1' is an intermediate response and indicates that the
server has received the request but has not finished processing it. For
example, IIS initially replies with 100 Continue when it receives a POST
request and then with 200 OK once it has been processed (See 6.
Methods)

2xx - Successful

These codes are used when a request has been successfully processed.
For example, the value 200 is used when the requested resource is being
returned to the HTTP client in the body of the response message.

3xx - Redirection

Codes starting with a '3' indicate that the request was processed, but the
browser should get the resource from another location. Some examples
are:

302 The requested resource has been temporarily moved and the browser
should issue a request to the URL supplied in the Location response
header. (See 7. Redirection)

304 The requested resource has not been modified and the browser should
read from its local cache instead. The Content-Length header will be
zero or absent because content is never returned with a 304 response
(See 5. Caching for more detail)

4xx - Client Error


The server returns these codes when they is a problem with the client's
request. Here are some examples:

401 Anonymous clients are not authorized to view the requested content and
must provide authentication information in the WWW-
Authenticate request header. (See 10. Authentication for more detail)

404 The requested resource does not exist on the server

5xx - Server Error

A status code starting with the digit 5 indicates that an error occurred on
the server while processing the request. For example:

500 An internal error occurred on the server. This may be because of an


application error or configuration problem

503 The service is currently unavailable, perhaps because of essential


maintenance or overloading

You might also like