Skip to main content

HTTP Examples

 HTTP Examples



This reading explores the contents of HTTP requests and responses in more depth.


Request Line

Every HTTP request begins with the request line.

This consists of the HTTP method, the requested resource and the HTTP protocol version.

GET /home.html HTTP/1.1 

In this example, GET is the HTTP method, /home.html is the resource requested and HTTP 1.1 is the protocol used.

HTTP Methods

HTTP methods indicate the action that the client wishes to perform on the web server resource.


Common HTTP methods are:

HTTP Method

Description

GET

The client requests a resource on the web server.

POST

The client submits data to a resource on the web server.

PUT

The client replaces a resource on the web server.

DELETE

The client deletes a resource on the web server.


HTTP Request Headers

After the request line, the HTTP headers are followed by a line break.

There are various possibilities when including an HTTP header in the HTTP request. A header is a case-insensitive name followed by a: and then followed by a value.

Common headers are:

  • The Host header specifies the host of the server and indicates where the resource is requested from.

  • The User-Agent header informs the web server of the application that is making the request. It often includes the operating system (Windows, Mac, Linux), version and application vendor.

  • The Accept header informs the web server what type of content the client will accept as the response.

  • The Accept-Language header indicates the language and optionally the locale that the client prefers.

  • The Content-type header indicates the type of content being transmitted in the request body.


HTTP Request Body

HTTP requests can optionally include a request body. A request body is often included when using the HTTP POST and PUT methods to transmit data.

HTTP Responses

When the web server is finished processing the HTTP request, it will send back an HTTP response.

The first line of the response is the status line. This line shows the client if the request was successful or if an error occurred.

HTTP/1.1 200 OK​ 

The line begins with the HTTP protocol version, followed by the status code and a reason phrase. The reason phrase is a textual representation of the status code.

HTTP Status Codes

The first digit of an HTTP status code indicates the category of the response: Information, Successful, Redirection, Client Error or Server Error.

The common status codes you'll encounter for each category are:


1XX Informational

Status Code

Reason Phrase

Description

100

Continue

The server received the request headers and should continue to send the request body.

101

Switching Protocols

The client has requested the server to switch protocols and the server has agreed to do so.



2XX Successfull

Status Code

Reason Phrase

Description

200

OK

Standard response returned by the server to indicate it successfully processed the request.

201

Created

The server successfully processed the request and a resource was created.

202

Accepted

The server accepted the request for processing but the processing has not yet been completed.

204

No Content

The server successfully processed the request but is not returning any content.


3XX Redirection

Status Code

Reason Phrase

Description

301

Moved Permanently

This request and all future requests should be sent to the returned location.

302

Found

This request should be sent to the returned location.


4XX Client Error

Status Code

Reason Phrase

Description

400

Bad Request

The server cannot process the request due to a client error, e.g., invalid request or transmitted data is too large.

401

Unauthorized

The client making the request is unauthorized and should authenticate.

403

Forbidden

The request was valid but the server is refusing to process it. This is usually returned due to the client having insufficient permissions for the website, e.g., requesting an administrator action but the user is not an administrator.

404

Not Found

The server did not find the requested resource.

405

Method Not Allowed

The web server does not support the HTTP method used.


5XX Server Error

Status Code

Reason Phrase

Description

500

Internal Server Error

A generic error status code given when an unexpected error or condition occurred while processing the request.

502

Bad Gateway

The web server received an invalid response from the Application Server.

503

Service Unavailable

The web server cannot process the request.

HTTP Response Headers

Following the status line, there are optional HTTP response headers followed by a line break.

Similar to the request headers, there are many possible HTTP headers that can be included in the HTTP response.

Common response headers are:


  • The Date header specifies the date and time the HTTP response was generated.

  • The Server header describes the web server software used to generate the response.

  • The Content-Length header describes the length of the response.

  • The Content-Type header describes the media type of the resource returned (e.g. HTML document, image, video).


HTTP Response Body

Following the HTTP response headers is the HTTP response body. This is the main content of the HTTP response.

This can contain images, video, HTML documents and other media types.

Comments

Popular posts from this blog

HTML Tutorial for Web Development and Design

HTML Tutorial for Web Development and Design HTML is the language of web  the structure of web pages is created with the help of Html  it is styled with the help of css  and logic is added to it with the help of javascript.  In 1989, Tim Berners-Lee established the http://www  and he created the Html in 1991.  Html was a very basic language at that time  which did not even have an image tag  well it is still a basic language even in today's time. In 1991, when other programming languages  were evolving in different fields  then Tim Berners-Lee thought that  it is very important to have a language for web developers as well  and it is very important to have a standard  he took it forward giving full support to html  and understood the problem of web developers  and those who were developing the browser  he sincerely wanted that  a modernization could come in the world of web development  and the pro...

CSS Web Development Tutorials

Learn CSS for free - A tutorial for beginners CSS (Cascading Style Sheets) makes pages look great and adequate. It's a fundamental piece of current web improvement and an absolute necessity have expertise for any website specialist and engineer. In this article, I'll give you a speedy prologue to assist you with getting everything rolling with CSS. I'm accepting that you have a fundamental comprehension of HTML , however other than that there are no requirements for this instructional exercise. Welcome to Learn CSS: This course breaks down the essentials of CSS into edible, straightforward pieces. Throughout the following couple of modules, you'll figure out how the center parts of CSS work and how to utilize them really in your tasks. Utilize the menu sheet by the "Learn CSS" logo to explore the modules. You'll learn CSS essentials like the container model, outpouring and particularity, flexbox, lattice and z-file. Furthermore, alongside these essentials,...

21 Interesting Web Development Project Ideas For Beginners [2022]

 21 Interesting Web Development Project Ideas For Beginners [2022] Web Development Project Ideas: With digital presence becoming a necessity for brands to expand and gain exposure among potential customers, the web development industry is taking off rapidly, and so is the demand for Web Developers. In fact, web development has emerged as a promising field right now, attracting aspirants from all educational and professional backgrounds. As industries continue facing fierce competition among fellow brands and services, the ones keeping up with trends steal the limelight.  The severe expansion of digitally engaged audiences has proved that web development is no more a choice but a necessity to reach a broader customer base, increase engagement and promote services.  Considering how web development is experiencing continuous growth with technological advancement, following web development trends is essential to sustain the audience’s volatile attention. Aspects like architec...