19.1 C
New York
Tuesday, September 28, 2021
HomeNetworking BasicsHTTP requests explained

HTTP requests explained

The internet is a global network of computers with each computer hosting varying information resources on its system. For two computers (a client and a server) to communicate or share information over the internet, they use HTTP (hypertext transfer protocol) to structure their requests and responses into standard, effective, and understandable communication. Today, we are going to explore what are HTTP requests during client<=>server communication.

What are HTTP Requests?

An HTTP request is a message sent by a client to a server calling for a response from the server. Server responses are usually actions performed according to the instruction within an HTTP request. The type of action is determined from the request method within the first line (request line) of an HTTP request message.

A good HTTP request message usually includes these items:

  1. Request Line – The first line in an HTTP request message. It’s comprised of 3 main things, which are:
  • Method – single word command that tells the server what action it should perform on a given resource
  • URL path of resource (resource location)
  • The protocol version of the HTTP

Below is a sample request line:

MethodRequest-URIHTTP-Version
GETw33d/protocols/rfc2616-sec5.htmlHTTP/1.1
  1. HTTP request headers (Zero or more)

HTTP headers allow the sending of additional information within HTTP requests or responses between a client and a server. An HTTP request header is only used in HTTP requests. Additional information sent to a includes data about the HTTP request, data about the client, etc. A request header acts as a modifier on the HTTP request. Here are some HTTP request header examples:

  • User-Agent
  • Accept-*
  • Authorization
  • Host
  • If-Match
  • If-Modified-Since
  • If-None-Match
  • If-Range
  • If-Unmodified-Since
  1. HTTP Message body

This is a part of an HTTP request message that is not always necessary. Its inclusion depends upon the request method used and the client’s preferences.

Recommended Reading:

What is HTTPS? HTTPS explained here

HTTP requests include HTTP request methods which is the key part of any HTTP request. HTTP request methods determine the type of action an HTTP request commands the server to do. Some people use HTTP requests interchangeably with HTTP request methods. Here are the HTTP request methods:

Types of HTTP Request Methods

GET

GET is an HTTP request method aim to retrieve a specific resource from the server. The resource or information is located or identified through the request-URL. It’s one of the most commonly used HTTP request methods.

HEAD

A HEAD request method is similar to a GET method, but the difference is that while a GET response has a message-body, a HEAD response doesn’t. A HEAD request is ideal for retrieving only the metadata without the associated content. The metadata is written according to the headers. HEAD’s most common use case is when you are testing the accessibility, validity, and modifications of hypertext links.

POST

On the internet, a POST method is used to request a server to create or update an information resource. The information needed from the client by the server to create or update a resource is archived within the body of an HTTP request.

This information is often user-generated. For example, a POST request is used when a user updates their profile picture or information.

PUT

PUT is similar to POST, as they are both used by the client to send data to the server for the creation or updating of a resource. However, the difference between a POST and a PUT method is that PUT requests are idempotent, meaning that the server response will always be the same regardless of how many times a PUT request is called.

DELETE

A DELETE request is used by a client to delete or remove specific resources on the server. Specific URL(s) or location paths within the request body point out the resource to be deleted.

TRACE

A TRACE request method is used to do a message loop-back test on the path between a client and a targeted resource. A loop-back test echoes what a received request so that the client can see what the server sees. A TRACE allows a client to check out the changes if there are any, made by intermediate servers along the path.

OPTIONS

An OPTIONS request method asks the server which HTTP methods it supports or allows on its hosted resources. This method is mainly used to check a web server’s functions by not targeting any resource but instead using an asterisk “*” in place of a resource location.

CONNECT

A CONNECT request method establishes an unencrypted TCP/IP communication tunnel between a client and a server. The tunnel facilitates HTTPS (SSL-encrypted) traffic through an HTTP proxy. un

PATCH

A PATCH method is similar to PUT and POST in that it modifies a resource on the server. The difference however is that a PATCH request method only applies partial modification to a resource.

Source –https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

HTTP Request Message Examples


A sample request message using a GET request method:

  • 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

A sample request message using a POST request method:

  • POST /cgi-bin/process.cgi HTTP/1.1
  • User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
  • Host: www.tutorialspoint.com
  • Content-Type: application/x-www-form-urlencoded
  • Content-Length: length
  • Accept-Language: en-us
  • Accept-Encoding: gzip, deflate
  • Connection: Keep-Alive
  • licenseID=string&content=string&/paramsXML=string

A sample request message using a POST request method passing plain XML to a web server:

  • 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: length
  • Accept-Language: en-us
  • Accept-Encoding: gzip, deflate
  • Connection: Keep-Alive
  • <?xml version=”1.0″ encoding=”utf-8″?>
  • <string xmlns=”http://clearforest.com/”>string</string>
LATEST ARTICLES

RELATED ARTICLES